Compare commits
No commits in common. "living-ai-rater" and "animal-rating-android-studio" have entirely different histories.
living-ai-
...
animal-rat
|
|
@ -1,2 +0,0 @@
|
||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
|
|
@ -4,6 +4,17 @@
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DropdownSelection timestamp="2025-11-24T18:35:29.331278100Z">
|
||||||
|
<Target type="DEFAULT_BOOT">
|
||||||
|
<handle>
|
||||||
|
<DeviceId pluginId="PhysicalDevice" identifier="serial=10BF45100J001X5" />
|
||||||
|
</handle>
|
||||||
|
</Target>
|
||||||
|
</DropdownSelection>
|
||||||
|
<DialogSelection />
|
||||||
|
</SelectionState>
|
||||||
|
<SelectionState runConfigName="release">
|
||||||
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
<option name="previewFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownSettings">
|
||||||
|
<option name="previewPanelProviderInfo">
|
||||||
|
<ProviderInfo name="Compose (experimental)" className="com.intellij.markdown.compose.preview.ComposePanelProvider" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -5,11 +5,13 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.example.livingai"
|
namespace = "com.example.animalrating"
|
||||||
compileSdk = 36
|
compileSdk {
|
||||||
|
version = release(36)
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.example.livingai"
|
applicationId = "com.example.animalrating"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
|
|
@ -25,6 +27,7 @@ android {
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
|
signingConfig = signingConfigs.getByName("debug")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|
@ -36,22 +39,23 @@ android {
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
viewBinding = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
val cameraxVersion = "1.5.0-alpha03"
|
val cameraxVersion = "1.5.1"
|
||||||
implementation("androidx.appcompat:appcompat:1.7.0")
|
implementation("androidx.appcompat:appcompat:1.7.0")
|
||||||
implementation("androidx.cardview:cardview:1.0.0")
|
implementation("androidx.cardview:cardview:1.0.0")
|
||||||
implementation("com.google.android.material:material:1.12.0")
|
implementation("com.google.android.material:material:1.12.0")
|
||||||
implementation("androidx.camera:camera-core:${cameraxVersion}")
|
implementation("androidx.camera:camera-core:$cameraxVersion")
|
||||||
implementation("androidx.camera:camera-camera2:${cameraxVersion}")
|
implementation("androidx.camera:camera-camera2:$cameraxVersion")
|
||||||
implementation("androidx.camera:camera-lifecycle:${cameraxVersion}")
|
implementation("androidx.camera:camera-lifecycle:$cameraxVersion")
|
||||||
implementation("androidx.camera:camera-view:${cameraxVersion}")
|
implementation("androidx.camera:camera-view:$cameraxVersion")
|
||||||
implementation("androidx.camera:camera-mlkit-vision:${cameraxVersion}")
|
implementation("androidx.camera:camera-mlkit-vision:$cameraxVersion")
|
||||||
|
|
||||||
|
// ML Kit Object Detection
|
||||||
implementation("com.google.mlkit:object-detection:17.0.2")
|
implementation("com.google.mlkit:object-detection:17.0.2")
|
||||||
|
// ML Kit Subject Segmentation (Google Play Services version)
|
||||||
implementation("com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1")
|
implementation("com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1")
|
||||||
|
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
|
|
@ -62,8 +66,6 @@ dependencies {
|
||||||
implementation(libs.androidx.compose.ui.graphics)
|
implementation(libs.androidx.compose.ui.graphics)
|
||||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||||
implementation(libs.androidx.compose.material3)
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation(libs.androidx.appcompat)
|
|
||||||
implementation(libs.material)
|
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai
|
package com.example.animalrating
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
|
@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
|
||||||
fun useAppContext() {
|
fun useAppContext() {
|
||||||
// Context of the app under test.
|
// Context of the app under test.
|
||||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||||
assertEquals("com.example.livingai", appContext.packageName)
|
assertEquals("com.example.animalrating", appContext.packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera" />
|
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-feature android:name="android.hardware.camera" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
|
||||||
|
|
@ -16,47 +16,45 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.LivingAI">
|
android:theme="@style/Theme.AnimalRating"
|
||||||
|
android:requestLegacyExternalStorage="true">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.page.HomeActivity"
|
android:name=".HomeActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/title_home"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.LivingAI">
|
android:theme="@style/Theme.AnimalRating">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.page.GalleryActivity"
|
android:name=".CowSelectionActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_gallery"
|
android:theme="@style/Theme.AnimalRating" />
|
||||||
android:theme="@style/Theme.LivingAI" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.page.AddAnimalProfileActivity"
|
android:name=".CameraProcessor"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_add_cow_details"
|
android:theme="@style/Theme.AnimalRating" />
|
||||||
android:theme="@style/Theme.LivingAI"
|
|
||||||
android:windowSoftInputMode="adjustResize" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.page.RatingActivity"
|
android:name=".GalleryActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_rate_cow"
|
android:theme="@style/Theme.AnimalRating" />
|
||||||
android:theme="@style/Theme.LivingAI" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.page.FullScreenImageActivity"
|
android:name=".FullScreenImageActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@style/Theme.LivingAI" />
|
android:theme="@style/Theme.AnimalRating" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".camera.CameraActivity"
|
android:name=".RatingActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@style/Theme.LivingAI" />
|
android:theme="@style/Theme.AnimalRating" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,373 @@
|
||||||
|
package com.example.animalrating
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Matrix
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.provider.MediaStore
|
||||||
|
import android.util.Log
|
||||||
|
import android.util.Size
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.camera.core.ExperimentalGetImage
|
||||||
|
import androidx.camera.core.ImageAnalysis
|
||||||
|
import androidx.camera.core.ImageCapture
|
||||||
|
import androidx.camera.core.ImageCaptureException
|
||||||
|
import androidx.camera.core.ImageProxy
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.example.animalrating.ml.CowAnalyzer
|
||||||
|
import com.example.animalrating.ui.SilhouetteOverlay
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
class CameraProcessor : AppCompatActivity(), CowAnalyzer.CowListener {
|
||||||
|
|
||||||
|
private lateinit var previewView: PreviewView
|
||||||
|
private lateinit var overlay: SilhouetteOverlay
|
||||||
|
private lateinit var segmentationOverlay: ImageView
|
||||||
|
private lateinit var savedMaskOverlay: ImageView
|
||||||
|
private var imageCapture: ImageCapture? = null
|
||||||
|
private lateinit var frameProcessor: FrameProcessor
|
||||||
|
|
||||||
|
private val cameraExecutor = Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
|
private var cowName: String? = null
|
||||||
|
private var orientation: String? = null
|
||||||
|
private var currentMask: Bitmap? = null
|
||||||
|
private var savedMaskBitmap: Bitmap? = null
|
||||||
|
private var isPhotoTaken = false
|
||||||
|
private var matchThreshold = 75
|
||||||
|
private var algorithm = HomeActivity.ALGORITHM_HAMMING
|
||||||
|
private var isAutoCapture = true
|
||||||
|
private var isMaskDisplayEnabled = false
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
|
||||||
|
cowName = intent.getStringExtra("COW_NAME")
|
||||||
|
orientation = intent.getStringExtra("ORIENTATION")
|
||||||
|
|
||||||
|
// Load settings
|
||||||
|
val prefs = getSharedPreferences("AnimalRatingPrefs", MODE_PRIVATE)
|
||||||
|
matchThreshold = prefs.getInt("THRESHOLD", 75)
|
||||||
|
algorithm = prefs.getString("ALGORITHM", HomeActivity.ALGORITHM_HAMMING) ?: HomeActivity.ALGORITHM_HAMMING
|
||||||
|
isAutoCapture = prefs.getBoolean(HomeActivity.PREF_AUTO_CAPTURE, true)
|
||||||
|
isMaskDisplayEnabled = prefs.getBoolean(HomeActivity.PREF_MASK_DISPLAY, false)
|
||||||
|
|
||||||
|
// Set orientation based on selected view
|
||||||
|
if (orientation == "front" || orientation == "back") {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
} else {
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||||
|
}
|
||||||
|
|
||||||
|
previewView = findViewById(R.id.cameraPreview)
|
||||||
|
overlay = findViewById(R.id.silhouetteOverlay)
|
||||||
|
segmentationOverlay = findViewById(R.id.segmentationOverlay)
|
||||||
|
savedMaskOverlay = findViewById(R.id.savedMaskOverlay)
|
||||||
|
|
||||||
|
findViewById<MaterialButton>(R.id.btnExit).setOnClickListener {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
val btnShutter = findViewById<MaterialButton>(R.id.btnShutter)
|
||||||
|
val btnToggle = findViewById<MaterialButton>(R.id.btnToggleCaptureMode)
|
||||||
|
|
||||||
|
btnShutter.setOnClickListener {
|
||||||
|
takePhoto()
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCaptureModeUI()
|
||||||
|
|
||||||
|
btnToggle.setOnClickListener {
|
||||||
|
isAutoCapture = !isAutoCapture
|
||||||
|
// Save preference for persistence if desired, or just toggle for session
|
||||||
|
prefs.edit().putBoolean(HomeActivity.PREF_AUTO_CAPTURE, isAutoCapture).apply()
|
||||||
|
updateCaptureModeUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
frameProcessor = FrameProcessor()
|
||||||
|
|
||||||
|
val silhouetteId = intent.getIntExtra("SILHOUETTE_ID", 0)
|
||||||
|
overlay.setSilhouette(silhouetteId)
|
||||||
|
|
||||||
|
// Need to wait for layout to get width/height for scaling mask correctly
|
||||||
|
savedMaskOverlay.post {
|
||||||
|
loadSavedMask()
|
||||||
|
}
|
||||||
|
|
||||||
|
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCaptureModeUI() {
|
||||||
|
val btnShutter = findViewById<MaterialButton>(R.id.btnShutter)
|
||||||
|
val btnToggle = findViewById<MaterialButton>(R.id.btnToggleCaptureMode)
|
||||||
|
|
||||||
|
if (isAutoCapture) {
|
||||||
|
btnShutter.visibility = View.GONE
|
||||||
|
// Auto Mode: Eye Icon, Dark Background
|
||||||
|
btnToggle.setIconResource(android.R.drawable.ic_menu_view)
|
||||||
|
btnToggle.setIconTintResource(android.R.color.white)
|
||||||
|
btnToggle.setBackgroundColor(Color.parseColor("#6D4C41"))
|
||||||
|
btnToggle.alpha = 1.0f
|
||||||
|
} else {
|
||||||
|
btnShutter.visibility = View.VISIBLE
|
||||||
|
// Manual Mode: Eye Icon (Grey/Transparent) - Requested to keep Eye icon
|
||||||
|
btnToggle.setIconResource(android.R.drawable.ic_menu_view)
|
||||||
|
btnToggle.setIconTintResource(android.R.color.darker_gray)
|
||||||
|
btnToggle.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
btnToggle.alpha = 0.7f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun takePhoto() {
|
||||||
|
if (isPhotoTaken) return
|
||||||
|
isPhotoTaken = true
|
||||||
|
|
||||||
|
val imageCapture = imageCapture ?: return
|
||||||
|
|
||||||
|
val name = cowName ?: "unknown"
|
||||||
|
val side = orientation ?: "unknown"
|
||||||
|
val silhouetteId = intent.getIntExtra("SILHOUETTE_ID", 0)
|
||||||
|
|
||||||
|
// Find current count for this cow and orientation
|
||||||
|
val cowFolder = StorageUtils.getCowImageFolder(name)
|
||||||
|
|
||||||
|
val existingFiles = cowFolder.listFiles { _, fname ->
|
||||||
|
fname.startsWith("${name}_${side}_") && fname.endsWith(".jpg")
|
||||||
|
}
|
||||||
|
val count = (existingFiles?.size ?: 0) + 1
|
||||||
|
|
||||||
|
if (!cowFolder.exists()) {
|
||||||
|
cowFolder.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
val filename = "${name}_${side}_${count}.jpg"
|
||||||
|
val file = File(cowFolder, filename)
|
||||||
|
|
||||||
|
val outputOptions = ImageCapture.OutputFileOptions.Builder(file).build()
|
||||||
|
|
||||||
|
imageCapture.takePicture(
|
||||||
|
outputOptions,
|
||||||
|
ContextCompat.getMainExecutor(this),
|
||||||
|
object : ImageCapture.OnImageSavedCallback {
|
||||||
|
override fun onError(exc: ImageCaptureException) {
|
||||||
|
Log.e("CameraProcessor", "Photo capture failed: ${exc.message}", exc)
|
||||||
|
Toast.makeText(baseContext, StringProvider.getString("toast_capture_failed"), Toast.LENGTH_SHORT).show()
|
||||||
|
isPhotoTaken = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onImageSaved(output: ImageCapture.OutputFileResults) {
|
||||||
|
// Correct rotation based on current orientation
|
||||||
|
try {
|
||||||
|
val bitmap = BitmapFactory.decodeFile(file.absolutePath)
|
||||||
|
val matrix = Matrix()
|
||||||
|
|
||||||
|
val rotation = if (orientation == "front" || orientation == "back") 90f else 0f
|
||||||
|
|
||||||
|
if (rotation != 0f) {
|
||||||
|
matrix.postRotate(rotation)
|
||||||
|
val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
||||||
|
FileOutputStream(file).use { out ->
|
||||||
|
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val retakePath = intent.getStringExtra("RETAKE_IMAGE_PATH")
|
||||||
|
if (!retakePath.isNullOrEmpty()) {
|
||||||
|
val oldFile = File(retakePath)
|
||||||
|
if (oldFile.exists()) {
|
||||||
|
oldFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val msg = "${StringProvider.getString("toast_saved_as")} $filename"
|
||||||
|
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
// Navigate to FullScreenImageActivity
|
||||||
|
val intent = Intent(this@CameraProcessor, FullScreenImageActivity::class.java)
|
||||||
|
intent.putExtra("IMAGE_PATH", file.absolutePath)
|
||||||
|
intent.putExtra("ALLOW_RETAKE", true)
|
||||||
|
intent.putExtra("COW_NAME", cowName)
|
||||||
|
intent.putExtra("ORIENTATION", orientation)
|
||||||
|
intent.putExtra("SILHOUETTE_ID", silhouetteId)
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("CameraProcessor", "Error saving image", e)
|
||||||
|
Toast.makeText(baseContext, StringProvider.getString("toast_error_saving_image"), Toast.LENGTH_SHORT).show()
|
||||||
|
isPhotoTaken = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveToGallery(file: File) {
|
||||||
|
// Removed
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadSavedMask() {
|
||||||
|
val side = orientation ?: "unknown"
|
||||||
|
val filename = "${side}_mask.png"
|
||||||
|
val file = File(filesDir, filename)
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
try {
|
||||||
|
val savedBitmap = BitmapFactory.decodeFile(file.absolutePath)
|
||||||
|
|
||||||
|
if (savedBitmap != null) {
|
||||||
|
// Apply green color filter for visualization
|
||||||
|
if (isMaskDisplayEnabled) {
|
||||||
|
val greenMask = applyGreenColor(savedBitmap)
|
||||||
|
|
||||||
|
// Calculate scale to match FIT_CENTER logic of SilhouetteOverlay
|
||||||
|
val viewW = savedMaskOverlay.width.toFloat()
|
||||||
|
val viewH = savedMaskOverlay.height.toFloat()
|
||||||
|
|
||||||
|
if (viewW > 0 && viewH > 0) {
|
||||||
|
val bmpW = greenMask.width.toFloat()
|
||||||
|
val bmpH = greenMask.height.toFloat()
|
||||||
|
|
||||||
|
val scale = kotlin.math.min(viewW / bmpW, viewH / bmpH)
|
||||||
|
val scaledW = (bmpW * scale).toInt()
|
||||||
|
val scaledH = (bmpH * scale).toInt()
|
||||||
|
|
||||||
|
if (scaledW > 0 && scaledH > 0) {
|
||||||
|
val scaledBitmap = Bitmap.createScaledBitmap(greenMask, scaledW, scaledH, true)
|
||||||
|
savedMaskOverlay.setImageBitmap(scaledBitmap)
|
||||||
|
savedMaskOverlay.scaleType = ImageView.ScaleType.FIT_CENTER // Ensure it centers
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback if view size not ready yet, though post() should handle it
|
||||||
|
savedMaskOverlay.setImageBitmap(greenMask)
|
||||||
|
}
|
||||||
|
|
||||||
|
savedMaskOverlay.alpha = 0.5f
|
||||||
|
} else {
|
||||||
|
savedMaskOverlay.setImageDrawable(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare mask for analysis (640x480 target)
|
||||||
|
// We should ideally match the visible part of the preview
|
||||||
|
// For simplicity, keeping original scaling logic for analysis as it might depend on full frame
|
||||||
|
// However, if the overlay is FIT_CENTER, the analysis should likely respect that aspect ratio too
|
||||||
|
// But for now, let's just fix the visual overlay as requested.
|
||||||
|
|
||||||
|
val isPortrait = (side == "front" || side == "back")
|
||||||
|
val width = if (isPortrait) 480 else 640
|
||||||
|
val height = if (isPortrait) 640 else 480
|
||||||
|
|
||||||
|
savedMaskBitmap = Bitmap.createScaledBitmap(savedBitmap, width, height, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("CameraProcessor", "Error loading saved mask", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyGreenColor(original: Bitmap): Bitmap {
|
||||||
|
val width = original.width
|
||||||
|
val height = original.height
|
||||||
|
val pixels = IntArray(width * height)
|
||||||
|
original.getPixels(pixels, 0, width, 0, 0, width, height)
|
||||||
|
|
||||||
|
for (i in pixels.indices) {
|
||||||
|
val alpha = (pixels[i] shr 24) and 0xff
|
||||||
|
if (alpha > 10) {
|
||||||
|
// Set to Green with original alpha
|
||||||
|
pixels[i] = Color.argb(alpha, 0, 255, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val requestPermissionLauncher =
|
||||||
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
||||||
|
if (granted) startCamera()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startCamera() {
|
||||||
|
val providerFuture = ProcessCameraProvider.getInstance(this)
|
||||||
|
|
||||||
|
providerFuture.addListener({
|
||||||
|
val cameraProvider = providerFuture.get()
|
||||||
|
|
||||||
|
val preview = androidx.camera.core.Preview.Builder().build()
|
||||||
|
preview.surfaceProvider = previewView.surfaceProvider
|
||||||
|
|
||||||
|
imageCapture = ImageCapture.Builder()
|
||||||
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val analyzer = ImageAnalysis.Builder()
|
||||||
|
.setTargetResolution(Size(640, 480))
|
||||||
|
.setBackpressureStrategy(
|
||||||
|
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.also {
|
||||||
|
it.setAnalyzer(cameraExecutor, CowAnalyzer(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraProvider.unbindAll()
|
||||||
|
cameraProvider.bindToLifecycle(
|
||||||
|
this,
|
||||||
|
androidx.camera.core.CameraSelector.DEFAULT_BACK_CAMERA,
|
||||||
|
preview,
|
||||||
|
imageCapture,
|
||||||
|
analyzer
|
||||||
|
)
|
||||||
|
|
||||||
|
}, ContextCompat.getMainExecutor(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
override fun onFrame(imageProxy: ImageProxy) {
|
||||||
|
if (isPhotoTaken) {
|
||||||
|
imageProxy.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val isPortrait = (orientation == "front" || orientation == "back")
|
||||||
|
|
||||||
|
frameProcessor.processFrame(imageProxy, savedMaskBitmap, isPortrait, matchThreshold, algorithm)
|
||||||
|
.addOnSuccessListener { result ->
|
||||||
|
runOnUiThread {
|
||||||
|
if (result.mask != null) {
|
||||||
|
currentMask = result.mask
|
||||||
|
if (isMaskDisplayEnabled) {
|
||||||
|
segmentationOverlay.setImageBitmap(result.mask)
|
||||||
|
} else {
|
||||||
|
segmentationOverlay.setImageDrawable(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isAutoCapture && result.isMatch) {
|
||||||
|
takePhoto()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.addOnFailureListener { e ->
|
||||||
|
Log.e("CameraProcessor", "Frame processing error", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.page
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
|
@ -19,10 +19,6 @@ import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.camera.CameraActivity
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import com.example.livingai.storage.StorageUtils
|
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -32,19 +28,21 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class AddAnimalProfileActivity : AppCompatActivity() {
|
class CowSelectionActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private var currentCowName: String? = null
|
private var currentCowName: String? = null
|
||||||
private lateinit var imagesContainer: LinearLayout
|
private lateinit var imagesContainer: LinearLayout
|
||||||
private val storagePermissionCode = 101
|
private val storagePermissionCode = 101
|
||||||
private val orientationViews = mutableMapOf<String, View>()
|
private val orientationViews = mutableMapOf<String, View>()
|
||||||
private val initialImagePaths = mutableSetOf<String>()
|
private val initialImagePaths = mutableSetOf<String>()
|
||||||
private val orientationList = Constants.ORIENTATION_NAMES
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_cow_selection)
|
setContentView(R.layout.activity_cow_selection)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
setupUIStrings()
|
||||||
|
|
||||||
val toolbar = findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar)
|
val toolbar = findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar)
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||||
|
|
@ -53,8 +51,6 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUILabels()
|
|
||||||
|
|
||||||
initializeDefaultMasks()
|
initializeDefaultMasks()
|
||||||
setupDropdowns()
|
setupDropdowns()
|
||||||
|
|
||||||
|
|
@ -71,9 +67,13 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
loadCowDetails(currentCowName!!)
|
loadCowDetails(currentCowName!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (orientation in orientationList) {
|
orientationViews["left"] = findViewById(R.id.btnLeft)
|
||||||
orientationViews[orientation] = findViewById(resources.getIdentifier(orientation, "id", packageName))
|
orientationViews["right"] = findViewById(R.id.btnRight)
|
||||||
}
|
orientationViews["angle"] = findViewById(R.id.btnTop)
|
||||||
|
orientationViews["front"] = findViewById(R.id.btnFront)
|
||||||
|
orientationViews["back"] = findViewById(R.id.btnBack)
|
||||||
|
orientationViews["left_angle"] = findViewById(R.id.btnLeftAngle)
|
||||||
|
orientationViews["right_angle"] = findViewById(R.id.btnRightAngle)
|
||||||
|
|
||||||
findViewById<Button>(R.id.btnNewCow).setOnClickListener {
|
findViewById<Button>(R.id.btnNewCow).setOnClickListener {
|
||||||
if (checkStoragePermissions()) {
|
if (checkStoragePermissions()) {
|
||||||
|
|
@ -89,36 +89,6 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUILabels() {
|
|
||||||
findViewById<TextView>(R.id.tvToolbarTitle).text = getString(R.string.title_cow_selection)
|
|
||||||
findViewById<TextView>(R.id.tvAddCowDetails).text = getString(R.string.title_add_cow_details)
|
|
||||||
findViewById<TextView>(R.id.tvLabelSpecies).text = getString(R.string.label_species)
|
|
||||||
findViewById<TextView>(R.id.tvLabelBreed).text = getString(R.string.label_breed)
|
|
||||||
findViewById<TextView>(R.id.tvLabelAge).text = getString(R.string.label_age)
|
|
||||||
findViewById<TextView>(R.id.tvLabelMilk).text = getString(R.string.label_milk_yield)
|
|
||||||
findViewById<TextView>(R.id.tvLabelCalving).text = getString(R.string.label_calving_no)
|
|
||||||
findViewById<TextView>(R.id.tvReproductiveStatus).text = getString(R.string.label_reproductive_status)
|
|
||||||
findViewById<RadioButton>(R.id.rbPregnant).text = getString(R.string.radio_pregnant)
|
|
||||||
findViewById<RadioButton>(R.id.rbCalved).text = getString(R.string.radio_calved)
|
|
||||||
findViewById<RadioButton>(R.id.rbNone).text = getString(R.string.radio_none)
|
|
||||||
|
|
||||||
findViewById<TextView>(R.id.tvLabelDescription).text = getString(R.string.hint_description)
|
|
||||||
findViewById<TextInputLayout>(R.id.tilDescription).hint = getString(R.string.hint_description)
|
|
||||||
|
|
||||||
findViewById<TextView>(R.id.tvUploadPhotos).text = getString(R.string.label_upload_photos)
|
|
||||||
|
|
||||||
findViewById<TextView>(R.id.tvFrontView).text = getString(R.string.text_front_view)
|
|
||||||
findViewById<TextView>(R.id.tvRearView).text = getString(R.string.text_rear_view)
|
|
||||||
findViewById<TextView>(R.id.tvLeftSide).text = getString(R.string.text_left_side)
|
|
||||||
findViewById<TextView>(R.id.tvRightSide).text = getString(R.string.text_right_side)
|
|
||||||
findViewById<TextView>(R.id.tvLeftAngle).text = getString(R.string.text_left_angle)
|
|
||||||
findViewById<TextView>(R.id.tvRightAngle).text = getString(R.string.text_right_angle)
|
|
||||||
findViewById<TextView>(R.id.tvAngleView).text = getString(R.string.text_angle_view)
|
|
||||||
|
|
||||||
findViewById<Button>(R.id.btnNewCow).text = getString(R.string.btn_save_profile)
|
|
||||||
findViewById<Button>(R.id.btnCancel).text = getString(R.string.btn_cancel)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadInitialImages() {
|
private fun loadInitialImages() {
|
||||||
val name = currentCowName ?: return
|
val name = currentCowName ?: return
|
||||||
val cowFolder = StorageUtils.getCowImageFolder(name)
|
val cowFolder = StorageUtils.getCowImageFolder(name)
|
||||||
|
|
@ -148,6 +118,36 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupUIStrings() {
|
||||||
|
findViewById<TextView>(R.id.tvToolbarTitle).text = StringProvider.getString("title_cow_selection")
|
||||||
|
findViewById<TextView>(R.id.tvAddCowDetails).text = StringProvider.getString("title_add_cow_details")
|
||||||
|
|
||||||
|
// Using hint_ keys for the new labels as they contain the appropriate text (e.g. "Species", "Breed")
|
||||||
|
findViewById<TextView>(R.id.tvLabelSpecies).text = StringProvider.getString("hint_species")
|
||||||
|
findViewById<TextView>(R.id.tvLabelBreed).text = StringProvider.getString("hint_breed")
|
||||||
|
findViewById<TextView>(R.id.tvLabelAge).text = StringProvider.getString("hint_age")
|
||||||
|
findViewById<TextView>(R.id.tvLabelMilk).text = StringProvider.getString("hint_milk_yield")
|
||||||
|
findViewById<TextView>(R.id.tvLabelCalving).text = StringProvider.getString("hint_calving_number")
|
||||||
|
findViewById<TextView>(R.id.tvLabelDescription).text = StringProvider.getString("hint_description")
|
||||||
|
|
||||||
|
findViewById<TextInputLayout>(R.id.tilSpecies).hint = null
|
||||||
|
findViewById<TextInputLayout>(R.id.tilBreed).hint = null
|
||||||
|
findViewById<TextInputLayout>(R.id.tilAge).hint = null
|
||||||
|
findViewById<TextInputLayout>(R.id.tilMilk).hint = null
|
||||||
|
findViewById<TextInputLayout>(R.id.tilCalving).hint = null
|
||||||
|
findViewById<TextInputLayout>(R.id.tilDescription).hint = null
|
||||||
|
|
||||||
|
findViewById<TextView>(R.id.tvReproductiveStatus).text = StringProvider.getString("label_reproductive_status")
|
||||||
|
findViewById<RadioButton>(R.id.rbPregnant).text = StringProvider.getString("radio_pregnant")
|
||||||
|
findViewById<RadioButton>(R.id.rbCalved).text = StringProvider.getString("radio_calved")
|
||||||
|
findViewById<RadioButton>(R.id.rbNone).text = StringProvider.getString("radio_none")
|
||||||
|
|
||||||
|
findViewById<TextView>(R.id.tvUploadPhotos).text = StringProvider.getString("label_upload_photos")
|
||||||
|
|
||||||
|
findViewById<Button>(R.id.btnNewCow).text = StringProvider.getString("btn_save_profile")
|
||||||
|
findViewById<Button>(R.id.btnCancel).text = StringProvider.getString("btn_cancel")
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkStoragePermissions(): Boolean {
|
private fun checkStoragePermissions(): Boolean {
|
||||||
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||||
android.os.Environment.isExternalStorageManager()
|
android.os.Environment.isExternalStorageManager()
|
||||||
|
|
@ -182,8 +182,11 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
val speciesDisplay = findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).text.toString()
|
val speciesDisplay = findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).text.toString()
|
||||||
val breedDisplay = findViewById<AutoCompleteTextView>(R.id.spinnerBreed).text.toString()
|
val breedDisplay = findViewById<AutoCompleteTextView>(R.id.spinnerBreed).text.toString()
|
||||||
|
|
||||||
val species = speciesDisplay
|
val speciesKey = StringProvider.getKeyForValue(speciesDisplay)
|
||||||
val breed = breedDisplay
|
val species = if (speciesKey != null) StringProvider.getStringEnglish(speciesKey) else speciesDisplay
|
||||||
|
|
||||||
|
val breedKey = StringProvider.getKeyForValue(breedDisplay)
|
||||||
|
val breed = if (breedKey != null) StringProvider.getStringEnglish(breedKey) else breedDisplay
|
||||||
|
|
||||||
val ageInput = findViewById<TextInputEditText>(R.id.etAge).text.toString()
|
val ageInput = findViewById<TextInputEditText>(R.id.etAge).text.toString()
|
||||||
val milkInput = findViewById<TextInputLayout>(R.id.tilMilk).editText?.text.toString()
|
val milkInput = findViewById<TextInputLayout>(R.id.tilMilk).editText?.text.toString()
|
||||||
|
|
@ -191,12 +194,13 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
val descriptionInput = findViewById<TextInputLayout>(R.id.tilDescription).editText?.text.toString()
|
val descriptionInput = findViewById<TextInputLayout>(R.id.tilDescription).editText?.text.toString()
|
||||||
|
|
||||||
val rgReproductive = findViewById<RadioGroup>(R.id.rgReproductiveStatus)
|
val rgReproductive = findViewById<RadioGroup>(R.id.rgReproductiveStatus)
|
||||||
val reproductiveStatus = when(rgReproductive?.checkedRadioButtonId) {
|
val reproductiveStatusKey = when(rgReproductive?.checkedRadioButtonId) {
|
||||||
R.id.rbPregnant -> getString(R.string.radio_pregnant)
|
R.id.rbPregnant -> "radio_pregnant"
|
||||||
R.id.rbCalved -> getString(R.string.radio_calved)
|
R.id.rbCalved -> "radio_calved"
|
||||||
R.id.rbNone -> getString(R.string.radio_none)
|
R.id.rbNone -> "radio_none"
|
||||||
else -> ""
|
else -> null
|
||||||
}
|
}
|
||||||
|
val reproductiveStatus = if (reproductiveStatusKey != null) StringProvider.getStringEnglish(reproductiveStatusKey) else ""
|
||||||
|
|
||||||
val csvHeader = "CowID,Species,Breed,Age,MilkYield,CalvingNumber,ReproductiveStatus,Description\n"
|
val csvHeader = "CowID,Species,Breed,Age,MilkYield,CalvingNumber,ReproductiveStatus,Description\n"
|
||||||
val csvRow = "$currentCowName,$species,$breed,$ageInput,$milkInput,$calvingInput,$reproductiveStatus,$descriptionInput\n"
|
val csvRow = "$currentCowName,$species,$breed,$ageInput,$milkInput,$calvingInput,$reproductiveStatus,$descriptionInput\n"
|
||||||
|
|
@ -226,11 +230,11 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(this, getString(R.string.toast_profile_saved), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, StringProvider.getString("toast_profile_saved"), Toast.LENGTH_SHORT).show()
|
||||||
finish()
|
finish()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Toast.makeText(this, getString(R.string.toast_error_saving_profile) + " ${e.message}", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, StringProvider.getString("toast_error_saving_profile") + " ${e.message}", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,10 +248,14 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
val record = lines.find { it.startsWith("$cowId,") }?.split(",") ?: return
|
val record = lines.find { it.startsWith("$cowId,") }?.split(",") ?: return
|
||||||
|
|
||||||
if (record.size >= 8) {
|
if (record.size >= 8) {
|
||||||
val displaySpecies = record[1]
|
val storedSpecies = record[1]
|
||||||
|
val speciesKey = StringProvider.getKeyForEnglishValue(storedSpecies)
|
||||||
|
val displaySpecies = if (speciesKey != null) StringProvider.getString(speciesKey) else storedSpecies
|
||||||
findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).setText(displaySpecies, false)
|
findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).setText(displaySpecies, false)
|
||||||
|
|
||||||
val displayBreed = record[2]
|
val storedBreed = record[2]
|
||||||
|
val breedKey = StringProvider.getKeyForEnglishValue(storedBreed)
|
||||||
|
val displayBreed = if (breedKey != null) StringProvider.getString(breedKey) else storedBreed
|
||||||
findViewById<AutoCompleteTextView>(R.id.spinnerBreed).setText(displayBreed, false)
|
findViewById<AutoCompleteTextView>(R.id.spinnerBreed).setText(displayBreed, false)
|
||||||
|
|
||||||
findViewById<TextInputEditText>(R.id.etAge).setText(record[3])
|
findViewById<TextInputEditText>(R.id.etAge).setText(record[3])
|
||||||
|
|
@ -255,18 +263,18 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
findViewById<TextInputLayout>(R.id.tilCalving).editText?.setText(record[5])
|
findViewById<TextInputLayout>(R.id.tilCalving).editText?.setText(record[5])
|
||||||
|
|
||||||
val storedStatus = record[6]
|
val storedStatus = record[6]
|
||||||
|
val statusKey = StringProvider.getKeyForEnglishValue(storedStatus)
|
||||||
|
|
||||||
if (storedStatus == getString(R.string.radio_pregnant)) {
|
when(statusKey) {
|
||||||
findViewById<RadioButton>(R.id.rbPregnant).isChecked = true
|
"radio_pregnant" -> findViewById<RadioButton>(R.id.rbPregnant).isChecked = true
|
||||||
} else if (storedStatus == getString(R.string.radio_calved)) {
|
"radio_calved" -> findViewById<RadioButton>(R.id.rbCalved).isChecked = true
|
||||||
findViewById<RadioButton>(R.id.rbCalved).isChecked = true
|
"radio_none" -> findViewById<RadioButton>(R.id.rbNone).isChecked = true
|
||||||
} else if (storedStatus == getString(R.string.radio_none)) {
|
else -> {
|
||||||
findViewById<RadioButton>(R.id.rbNone).isChecked = true
|
when (storedStatus) {
|
||||||
} else {
|
"Pregnant" -> findViewById<RadioButton>(R.id.rbPregnant).isChecked = true
|
||||||
when (storedStatus) {
|
"Calved" -> findViewById<RadioButton>(R.id.rbCalved).isChecked = true
|
||||||
"Pregnant" -> findViewById<RadioButton>(R.id.rbPregnant).isChecked = true
|
"None" -> findViewById<RadioButton>(R.id.rbNone).isChecked = true
|
||||||
"Calved" -> findViewById<RadioButton>(R.id.rbCalved).isChecked = true
|
}
|
||||||
"None" -> findViewById<RadioButton>(R.id.rbNone).isChecked = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,20 +287,20 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun setupDropdowns() {
|
private fun setupDropdowns() {
|
||||||
val species = listOf(
|
val species = listOf(
|
||||||
getString(R.string.species_cow),
|
StringProvider.getString("species_cow"),
|
||||||
getString(R.string.species_buffalo)
|
StringProvider.getString("species_buffalo")
|
||||||
)
|
)
|
||||||
val speciesAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, species)
|
val speciesAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, species)
|
||||||
findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).setAdapter(speciesAdapter)
|
findViewById<AutoCompleteTextView>(R.id.spinnerSpecies).setAdapter(speciesAdapter)
|
||||||
|
|
||||||
val breeds = listOf(
|
val breeds = listOf(
|
||||||
getString(R.string.breed_holstein),
|
StringProvider.getString("breed_holstein"),
|
||||||
getString(R.string.breed_jersey),
|
StringProvider.getString("breed_jersey"),
|
||||||
getString(R.string.breed_sahiwal),
|
StringProvider.getString("breed_sahiwal"),
|
||||||
getString(R.string.breed_gir),
|
StringProvider.getString("breed_gir"),
|
||||||
getString(R.string.breed_red_sindhi),
|
StringProvider.getString("breed_red_sindhi"),
|
||||||
getString(R.string.breed_murrah),
|
StringProvider.getString("breed_murrah"),
|
||||||
getString(R.string.breed_surti)
|
StringProvider.getString("breed_surti")
|
||||||
)
|
)
|
||||||
val breedAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, breeds)
|
val breedAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, breeds)
|
||||||
findViewById<AutoCompleteTextView>(R.id.spinnerBreed).setAdapter(breedAdapter)
|
findViewById<AutoCompleteTextView>(R.id.spinnerBreed).setAdapter(breedAdapter)
|
||||||
|
|
@ -304,10 +312,15 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeDefaultMasks() {
|
private fun initializeDefaultMasks() {
|
||||||
val orientationResources = orientationList.associate { orientation ->
|
val orientationResources = mapOf(
|
||||||
val resId = resources.getIdentifier(orientation, "drawable", packageName)
|
"left" to R.drawable.left,
|
||||||
orientation to resId
|
"right" to R.drawable.right,
|
||||||
}
|
"angle" to R.drawable.angle,
|
||||||
|
"front" to R.drawable.front,
|
||||||
|
"back" to R.drawable.back,
|
||||||
|
"leftangle" to R.drawable.leftangle,
|
||||||
|
"rightangle" to R.drawable.rightangle
|
||||||
|
)
|
||||||
|
|
||||||
orientationResources.forEach { (orientation, resId) ->
|
orientationResources.forEach { (orientation, resId) ->
|
||||||
val filename = "${orientation}_mask.png"
|
val filename = "${orientation}_mask.png"
|
||||||
|
|
@ -353,15 +366,19 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
private fun refreshCowImages() {
|
private fun refreshCowImages() {
|
||||||
val name = currentCowName ?: return
|
val name = currentCowName ?: return
|
||||||
|
|
||||||
val orientationResourcesPair = orientationList.associate { orientation ->
|
val orientations = mapOf(
|
||||||
val resId = resources.getIdentifier(orientation, "drawable", packageName)
|
"left" to Pair(R.drawable.left, R.id.btnLeft),
|
||||||
val btnId = resources.getIdentifier("btn${orientation}", "id", packageName)
|
"right" to Pair(R.drawable.right, R.id.btnRight),
|
||||||
orientation to Pair(resId, btnId)
|
"angle" to Pair(R.drawable.angle, R.id.btnTop),
|
||||||
}
|
"front" to Pair(R.drawable.front, R.id.btnFront),
|
||||||
|
"back" to Pair(R.drawable.back, R.id.btnBack),
|
||||||
|
"leftangle" to Pair(R.drawable.leftangle, R.id.btnLeftAngle),
|
||||||
|
"rightangle" to Pair(R.drawable.rightangle, R.id.btnRightAngle)
|
||||||
|
)
|
||||||
|
|
||||||
val cowImagesFolder = StorageUtils.getCowImageFolder(name)
|
val cowImagesFolder = StorageUtils.getCowImageFolder(name)
|
||||||
|
|
||||||
orientationResourcesPair.forEach { (orientation, pair) ->
|
orientations.forEach { (orientation, pair) ->
|
||||||
val (drawableId, viewId) = pair
|
val (drawableId, viewId) = pair
|
||||||
|
|
||||||
val files = if (cowImagesFolder.exists()) {
|
val files = if (cowImagesFolder.exists()) {
|
||||||
|
|
@ -375,16 +392,17 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
val container = findViewById<LinearLayout>(viewId)
|
val container = findViewById<LinearLayout>(viewId)
|
||||||
container.removeAllViews()
|
container.removeAllViews()
|
||||||
|
|
||||||
val label = when(orientation) {
|
val key = when(orientation) {
|
||||||
"front" -> getString(R.string.text_front_view)
|
"front" -> "text_front_view"
|
||||||
"back" -> getString(R.string.text_rear_view)
|
"back" -> "text_rear_view"
|
||||||
"left" -> getString(R.string.text_left_side)
|
"left" -> "text_left_side"
|
||||||
"right" -> getString(R.string.text_right_side)
|
"right" -> "text_right_side"
|
||||||
"angle" -> getString(R.string.text_angle_view)
|
"angle" -> "text_angle_view"
|
||||||
"leftangle" -> getString(R.string.text_left_angle)
|
"leftangle" -> "text_left_angle"
|
||||||
"rightangle" -> getString(R.string.text_right_angle)
|
"rightangle" -> "text_right_angle"
|
||||||
else -> orientation
|
else -> ""
|
||||||
}
|
}
|
||||||
|
val label = if (key.isNotEmpty()) StringProvider.getString(key) else orientation
|
||||||
|
|
||||||
if (latestFile != null && latestFile.exists()) {
|
if (latestFile != null && latestFile.exists()) {
|
||||||
val frameLayout = android.widget.FrameLayout(this)
|
val frameLayout = android.widget.FrameLayout(this)
|
||||||
|
|
@ -483,7 +501,7 @@ class AddAnimalProfileActivity : AppCompatActivity() {
|
||||||
container.addView(textView)
|
container.addView(textView)
|
||||||
|
|
||||||
container.setOnClickListener {
|
container.setOnClickListener {
|
||||||
val intent = Intent(this, CameraActivity::class.java)
|
val intent = Intent(this, CameraProcessor::class.java)
|
||||||
intent.putExtra("SILHOUETTE_ID", drawableId)
|
intent.putExtra("SILHOUETTE_ID", drawableId)
|
||||||
intent.putExtra("COW_NAME", currentCowName)
|
intent.putExtra("COW_NAME", currentCowName)
|
||||||
intent.putExtra("ORIENTATION", orientation)
|
intent.putExtra("ORIENTATION", orientation)
|
||||||
|
|
@ -0,0 +1,273 @@
|
||||||
|
package com.example.animalrating
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Matrix
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.camera.core.ExperimentalGetImage
|
||||||
|
import androidx.camera.core.ImageProxy
|
||||||
|
import com.google.android.gms.tasks.Task
|
||||||
|
import com.google.android.gms.tasks.TaskCompletionSource
|
||||||
|
import com.google.mlkit.vision.common.InputImage
|
||||||
|
import com.google.mlkit.vision.segmentation.subject.SubjectSegmentation
|
||||||
|
import com.google.mlkit.vision.segmentation.subject.SubjectSegmenterOptions
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
data class SegmentationResult(
|
||||||
|
val mask: Bitmap?,
|
||||||
|
val isMatch: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
class FrameProcessor {
|
||||||
|
|
||||||
|
private val isProcessing = AtomicBoolean(false)
|
||||||
|
private val processingExecutor = Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
|
private val options = SubjectSegmenterOptions.Builder()
|
||||||
|
.enableMultipleSubjects(
|
||||||
|
SubjectSegmenterOptions.SubjectResultOptions.Builder()
|
||||||
|
.enableConfidenceMask()
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
private val segmenter = SubjectSegmentation.getClient(options)
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
fun processFrame(
|
||||||
|
imageProxy: ImageProxy,
|
||||||
|
savedMask: Bitmap?,
|
||||||
|
isPortrait: Boolean,
|
||||||
|
thresholdPercent: Int = 75,
|
||||||
|
algorithm: String = HomeActivity.ALGORITHM_HAMMING
|
||||||
|
): Task<SegmentationResult> {
|
||||||
|
val taskCompletionSource = TaskCompletionSource<SegmentationResult>()
|
||||||
|
|
||||||
|
if (!isProcessing.compareAndSet(false, true)) {
|
||||||
|
imageProxy.close()
|
||||||
|
taskCompletionSource.setResult(SegmentationResult(null, false))
|
||||||
|
return taskCompletionSource.task
|
||||||
|
}
|
||||||
|
|
||||||
|
val mediaImage = imageProxy.image
|
||||||
|
if (mediaImage == null) {
|
||||||
|
isProcessing.set(false)
|
||||||
|
imageProxy.close()
|
||||||
|
taskCompletionSource.setResult(SegmentationResult(null, false))
|
||||||
|
return taskCompletionSource.task
|
||||||
|
}
|
||||||
|
|
||||||
|
val inputImage = InputImage.fromMediaImage(mediaImage, 0)
|
||||||
|
|
||||||
|
segmenter.process(inputImage)
|
||||||
|
.addOnSuccessListener(processingExecutor) { result ->
|
||||||
|
var bitmapMask: Bitmap? = null
|
||||||
|
val subject = result.subjects.firstOrNull()
|
||||||
|
val mask = subject?.confidenceMask
|
||||||
|
|
||||||
|
if (mask != null) {
|
||||||
|
val startX = subject.startX
|
||||||
|
val startY = subject.startY
|
||||||
|
val maskWidth = subject.width
|
||||||
|
val maskHeight = subject.height
|
||||||
|
|
||||||
|
val fullWidth = inputImage.width
|
||||||
|
val fullHeight = inputImage.height
|
||||||
|
|
||||||
|
if (mask.remaining() >= maskWidth * maskHeight) {
|
||||||
|
val colors = IntArray(fullWidth * fullHeight)
|
||||||
|
mask.rewind()
|
||||||
|
|
||||||
|
for (y in 0 until maskHeight) {
|
||||||
|
for (x in 0 until maskWidth) {
|
||||||
|
if (mask.get() > 0.5f) {
|
||||||
|
val destX = startX + x
|
||||||
|
val destY = startY + y
|
||||||
|
if (destX < fullWidth && destY < fullHeight) {
|
||||||
|
colors[destY * fullWidth + destX] = Color.argb(180, 255, 0, 255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val rawBitmap = Bitmap.createBitmap(colors, fullWidth, fullHeight, Bitmap.Config.ARGB_8888)
|
||||||
|
|
||||||
|
// Rotate and Scale if needed
|
||||||
|
bitmapMask = if (isPortrait) {
|
||||||
|
try {
|
||||||
|
val matrix = Matrix()
|
||||||
|
// Rotate 90 degrees
|
||||||
|
matrix.postRotate(90f)
|
||||||
|
|
||||||
|
// Assuming previous scaling logic might still be relevant if masks are consistently off
|
||||||
|
// But generally, we trust the geometry.
|
||||||
|
// If scaling up is happening unexpectedly, one could use:
|
||||||
|
// matrix.postScale(0.9f, 0.9f)
|
||||||
|
// For now, stick to rotation unless requested otherwise.
|
||||||
|
|
||||||
|
Bitmap.createBitmap(rawBitmap, 0, 0, rawBitmap.width, rawBitmap.height, matrix, true)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FrameProcessor", "Error rotating mask", e)
|
||||||
|
rawBitmap
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rawBitmap
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e("FrameProcessor", "Mask buffer size mismatch")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate match
|
||||||
|
var isMatch = false
|
||||||
|
if (bitmapMask != null && savedMask != null) {
|
||||||
|
// Scale current mask to match saved mask dimensions (640x480) for comparison
|
||||||
|
val comparisonMask = if (bitmapMask.width != savedMask.width || bitmapMask.height != savedMask.height) {
|
||||||
|
try {
|
||||||
|
Bitmap.createScaledBitmap(bitmapMask, savedMask.width, savedMask.height, true)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FrameProcessor", "Error scaling mask for comparison", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bitmapMask
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comparisonMask != null) {
|
||||||
|
// Map display strings to internal algorithm keys/logic
|
||||||
|
val algoKey = when(algorithm) {
|
||||||
|
StringProvider.getString("algo_euclidean") -> HomeActivity.ALGORITHM_EUCLIDEAN
|
||||||
|
StringProvider.getString("algo_jaccard") -> HomeActivity.ALGORITHM_JACCARD
|
||||||
|
else -> {
|
||||||
|
if (algorithm == HomeActivity.ALGORITHM_EUCLIDEAN || algorithm == HomeActivity.ALGORITHM_JACCARD) algorithm
|
||||||
|
else HomeActivity.ALGORITHM_HAMMING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isMatch = when (algoKey) {
|
||||||
|
HomeActivity.ALGORITHM_EUCLIDEAN -> calculateEuclideanDistance(savedMask, comparisonMask, thresholdPercent)
|
||||||
|
HomeActivity.ALGORITHM_JACCARD -> calculateJaccardSimilarity(savedMask, comparisonMask, thresholdPercent)
|
||||||
|
else -> calculateHammingDistance(savedMask, comparisonMask, thresholdPercent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taskCompletionSource.setResult(SegmentationResult(bitmapMask, isMatch))
|
||||||
|
}
|
||||||
|
.addOnFailureListener { e ->
|
||||||
|
Log.e("FrameProcessor", "Subject Segmentation failed", e)
|
||||||
|
taskCompletionSource.setException(e)
|
||||||
|
}
|
||||||
|
.addOnCompleteListener { _ ->
|
||||||
|
isProcessing.set(false)
|
||||||
|
imageProxy.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return taskCompletionSource.task
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateHammingDistance(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
||||||
|
if (mask1.width != mask2.width || mask1.height != mask2.height) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val width = mask1.width
|
||||||
|
val height = mask1.height
|
||||||
|
val pixels1 = IntArray(width * height)
|
||||||
|
val pixels2 = IntArray(width * height)
|
||||||
|
|
||||||
|
mask1.getPixels(pixels1, 0, width, 0, 0, width, height)
|
||||||
|
mask2.getPixels(pixels2, 0, width, 0, 0, width, height)
|
||||||
|
|
||||||
|
var distance = 0
|
||||||
|
for (i in pixels1.indices) {
|
||||||
|
val isSet1 = (pixels1[i] ushr 24) > 0
|
||||||
|
val isSet2 = (pixels2[i] ushr 24) > 0
|
||||||
|
|
||||||
|
if (isSet1 != isSet2) {
|
||||||
|
distance++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val totalPixels = width * height
|
||||||
|
val validThreshold = thresholdPercent.coerceIn(1, 100)
|
||||||
|
val allowedDistance = (totalPixels.toLong() * (100 - validThreshold)) / 100
|
||||||
|
|
||||||
|
return distance <= allowedDistance
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateEuclideanDistance(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
||||||
|
if (mask1.width != mask2.width || mask1.height != mask2.height) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val width = mask1.width
|
||||||
|
val height = mask1.height
|
||||||
|
val pixels1 = IntArray(width * height)
|
||||||
|
val pixels2 = IntArray(width * height)
|
||||||
|
|
||||||
|
mask1.getPixels(pixels1, 0, width, 0, 0, width, height)
|
||||||
|
mask2.getPixels(pixels2, 0, width, 0, 0, width, height)
|
||||||
|
|
||||||
|
var sumSq = 0L
|
||||||
|
for (i in pixels1.indices) {
|
||||||
|
// Simple binary comparison for Euclidean distance on masks
|
||||||
|
// Treat existence of pixel as 255, non-existence as 0
|
||||||
|
val val1 = if ((pixels1[i] ushr 24) > 0) 255 else 0
|
||||||
|
val val2 = if ((pixels2[i] ushr 24) > 0) 255 else 0
|
||||||
|
|
||||||
|
val diff = val1 - val2
|
||||||
|
sumSq += diff * diff
|
||||||
|
}
|
||||||
|
|
||||||
|
val euclideanDistance = sqrt(sumSq.toDouble())
|
||||||
|
val maxDistance = sqrt((width * height).toDouble()) * 255.0
|
||||||
|
|
||||||
|
val validThreshold = thresholdPercent.coerceIn(1, 100)
|
||||||
|
val allowedDistance = maxDistance * (100 - validThreshold) / 100.0
|
||||||
|
|
||||||
|
return euclideanDistance <= allowedDistance
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateJaccardSimilarity(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
||||||
|
if (mask1.width != mask2.width || mask1.height != mask2.height) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val width = mask1.width
|
||||||
|
val height = mask1.height
|
||||||
|
val pixels1 = IntArray(width * height)
|
||||||
|
val pixels2 = IntArray(width * height)
|
||||||
|
|
||||||
|
mask1.getPixels(pixels1, 0, width, 0, 0, width, height)
|
||||||
|
mask2.getPixels(pixels2, 0, width, 0, 0, width, height)
|
||||||
|
|
||||||
|
var intersection = 0
|
||||||
|
var union = 0
|
||||||
|
|
||||||
|
for (i in pixels1.indices) {
|
||||||
|
// mask1 is Saved Mask (Likely Inverted in StorageUtils: Subject is Transparent/0, Background is Black/255)
|
||||||
|
// But check how it's loaded. In CameraProcessor: loadSavedMask() -> decodeFile().
|
||||||
|
// If we assume saved mask is inverted (subject transparent), then alpha < 128 is subject.
|
||||||
|
val alpha1 = (pixels1[i] ushr 24) and 0xFF
|
||||||
|
val isSubject1 = alpha1 < 128
|
||||||
|
|
||||||
|
// mask2 is Live Mask (Subject is Magenta/180 alpha)
|
||||||
|
val alpha2 = (pixels2[i] ushr 24) and 0xFF
|
||||||
|
val isSubject2 = alpha2 > 0
|
||||||
|
|
||||||
|
if (isSubject1 && isSubject2) {
|
||||||
|
intersection++
|
||||||
|
}
|
||||||
|
if (isSubject1 || isSubject2) {
|
||||||
|
union++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (union == 0) return false
|
||||||
|
|
||||||
|
val jaccardIndex = (intersection.toDouble() / union.toDouble()) * 100
|
||||||
|
return jaccardIndex >= thresholdPercent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.page
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
|
@ -8,8 +8,6 @@ import android.widget.Button
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.camera.CameraActivity
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class FullScreenImageActivity : AppCompatActivity() {
|
class FullScreenImageActivity : AppCompatActivity() {
|
||||||
|
|
@ -18,6 +16,8 @@ class FullScreenImageActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_full_screen_image)
|
setContentView(R.layout.activity_full_screen_image)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
|
||||||
val imagePath = intent.getStringExtra("IMAGE_PATH")
|
val imagePath = intent.getStringExtra("IMAGE_PATH")
|
||||||
val allowRetake = intent.getBooleanExtra("ALLOW_RETAKE", false)
|
val allowRetake = intent.getBooleanExtra("ALLOW_RETAKE", false)
|
||||||
val cowName = intent.getStringExtra("COW_NAME")
|
val cowName = intent.getStringExtra("COW_NAME")
|
||||||
|
|
@ -35,11 +35,11 @@ class FullScreenImageActivity : AppCompatActivity() {
|
||||||
val btnRetake = findViewById<Button>(R.id.btnRetake)
|
val btnRetake = findViewById<Button>(R.id.btnRetake)
|
||||||
if (allowRetake && imagePath != null) {
|
if (allowRetake && imagePath != null) {
|
||||||
btnRetake.visibility = View.VISIBLE
|
btnRetake.visibility = View.VISIBLE
|
||||||
btnRetake.text = getString(R.string.btn_retake)
|
btnRetake.text = "Retake Photo"
|
||||||
|
|
||||||
btnRetake.setOnClickListener {
|
btnRetake.setOnClickListener {
|
||||||
// Launch camera to retake. Pass the current image path so CameraActivity can overwrite/delete it on success.
|
// Launch camera to retake. Pass the current image path so CameraProcessor can overwrite/delete it on success.
|
||||||
val intent = Intent(this, CameraActivity::class.java)
|
val intent = Intent(this, CameraProcessor::class.java)
|
||||||
intent.putExtra("SILHOUETTE_ID", silhouetteId)
|
intent.putExtra("SILHOUETTE_ID", silhouetteId)
|
||||||
intent.putExtra("COW_NAME", cowName)
|
intent.putExtra("COW_NAME", cowName)
|
||||||
intent.putExtra("ORIENTATION", orientation)
|
intent.putExtra("ORIENTATION", orientation)
|
||||||
|
|
@ -52,11 +52,11 @@ class FullScreenImageActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val btnBack = findViewById<ImageButton>(R.id.btnBack)
|
val btnBack = findViewById<ImageButton>(R.id.btnBack)
|
||||||
btnBack.contentDescription = getString(R.string.content_desc_back)
|
btnBack.contentDescription = StringProvider.getString("content_desc_back")
|
||||||
btnBack.setOnClickListener {
|
btnBack.setOnClickListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
findViewById<ImageView>(R.id.fullScreenImageView).contentDescription = getString(R.string.content_desc_full_screen_image)
|
findViewById<ImageView>(R.id.fullScreenImageView).contentDescription = StringProvider.getString("content_desc_full_screen_image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.page
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
|
@ -11,13 +11,11 @@ import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.cardview.widget.CardView
|
import androidx.cardview.widget.CardView
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.storage.StorageUtils
|
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class GalleryActivity : AppCompatActivity() {
|
class GalleryActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
|
@ -27,12 +25,16 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_gallery)
|
setContentView(R.layout.activity_gallery)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
|
||||||
val toolbar = findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar)
|
val toolbar = findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar)
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||||
|
|
||||||
|
findViewById<TextView>(R.id.tvToolbarTitle)?.text = StringProvider.getString("title_gallery")
|
||||||
|
|
||||||
toolbar.setNavigationOnClickListener {
|
toolbar.setNavigationOnClickListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,7 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
container = findViewById(R.id.galleryContainer)
|
container = findViewById(R.id.galleryContainer)
|
||||||
|
|
||||||
findViewById<FloatingActionButton>(R.id.fabAddCow).setOnClickListener {
|
findViewById<FloatingActionButton>(R.id.fabAddCow).setOnClickListener {
|
||||||
val intent = Intent(this, AddAnimalProfileActivity::class.java)
|
val intent = Intent(this, CowSelectionActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +91,7 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
radius = 16 * resources.displayMetrics.density
|
radius = 16 * resources.displayMetrics.density
|
||||||
cardElevation = 2 * resources.displayMetrics.density
|
cardElevation = 2 * resources.displayMetrics.density
|
||||||
setCardBackgroundColor(ContextCompat.getColor(context, R.color.surface_background))
|
setCardBackgroundColor(android.graphics.Color.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Horizontal Container (3:1 split)
|
// Horizontal Container (3:1 split)
|
||||||
|
|
@ -116,10 +118,10 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val nameView = TextView(this).apply {
|
val nameView = TextView(this).apply {
|
||||||
text = if (details.isNotEmpty()) "${getString(R.string.text_cow_id)} $cowName" else cowName
|
text = if (details.isNotEmpty()) "${StringProvider.getString("text_cow_id")} $cowName" else cowName
|
||||||
textSize = 20f
|
textSize = 20f
|
||||||
setTypeface(null, android.graphics.Typeface.BOLD)
|
setTypeface(null, android.graphics.Typeface.BOLD)
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.text_header_brown))
|
setTextColor(android.graphics.Color.parseColor("#3E2723"))
|
||||||
layoutParams = LinearLayout.LayoutParams(
|
layoutParams = LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
|
@ -131,34 +133,38 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
|
|
||||||
if (details.size >= 7) {
|
if (details.size >= 7) {
|
||||||
// Translate values for display
|
// Translate values for display
|
||||||
val displaySpecies = details.getOrElse(1) { "-" }
|
val storedSpecies = details.getOrElse(1) { "-" }
|
||||||
val displayBreed = details.getOrElse(2) { "-" }
|
val speciesKey = StringProvider.getKeyForEnglishValue(storedSpecies)
|
||||||
val displayStatus = details.getOrElse(6) { "-" }
|
val displaySpecies = if (speciesKey != null) StringProvider.getString(speciesKey) else storedSpecies
|
||||||
|
|
||||||
val age = details.getOrElse(3) { "-" }
|
val storedBreed = details.getOrElse(2) { "-" }
|
||||||
val milk = details.getOrElse(4) { "-" }
|
val breedKey = StringProvider.getKeyForEnglishValue(storedBreed)
|
||||||
val calving = details.getOrElse(5) { "-" }
|
val displayBreed = if (breedKey != null) StringProvider.getString(breedKey) else storedBreed
|
||||||
|
|
||||||
|
val storedStatus = details.getOrElse(6) { "-" }
|
||||||
|
val statusKey = StringProvider.getKeyForEnglishValue(storedStatus)
|
||||||
|
val displayStatus = if (statusKey != null) StringProvider.getString(statusKey) else storedStatus
|
||||||
|
|
||||||
val infoText = StringBuilder()
|
val infoText = StringBuilder()
|
||||||
infoText.append("${getString(R.string.label_species)} $displaySpecies ")
|
infoText.append("${StringProvider.getString("label_species")} $displaySpecies ")
|
||||||
infoText.append("${getString(R.string.label_breed)} $displayBreed\n")
|
infoText.append("${StringProvider.getString("label_breed")} $displayBreed\n")
|
||||||
infoText.append("${getString(R.string.label_age)} $age ${getString(R.string.unit_years)} ")
|
infoText.append("${StringProvider.getString("label_age")} ${details.getOrElse(3) { "-" }} ${StringProvider.getString("unit_years")} ")
|
||||||
infoText.append("${getString(R.string.label_milk_yield)} $milk ${getString(R.string.unit_liters)}\n")
|
infoText.append("${StringProvider.getString("label_milk_yield")} ${details.getOrElse(4) { "-" }} ${StringProvider.getString("unit_liters")}\n")
|
||||||
infoText.append("${getString(R.string.label_calving_no)} $calving ")
|
infoText.append("${StringProvider.getString("label_calving_no")} ${details.getOrElse(5) { "-" }} ")
|
||||||
infoText.append("${getString(R.string.label_status)} $displayStatus")
|
infoText.append("${StringProvider.getString("label_status")} $displayStatus")
|
||||||
|
|
||||||
val detailsView = TextView(this).apply {
|
val detailsView = TextView(this).apply {
|
||||||
text = infoText.toString()
|
text = infoText.toString()
|
||||||
textSize = 14f
|
textSize = 14f
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.text_brown))
|
setTextColor(android.graphics.Color.parseColor("#5D4037"))
|
||||||
setLineSpacing(10f, 1f)
|
setLineSpacing(10f, 1f)
|
||||||
}
|
}
|
||||||
leftLayout.addView(detailsView)
|
leftLayout.addView(detailsView)
|
||||||
} else {
|
} else {
|
||||||
val detailsView = TextView(this).apply {
|
val detailsView = TextView(this).apply {
|
||||||
text = getString(R.string.text_no_details)
|
text = "No details available"
|
||||||
textSize = 14f
|
textSize = 14f
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.text_brown))
|
setTextColor(android.graphics.Color.parseColor("#5D4037"))
|
||||||
}
|
}
|
||||||
leftLayout.addView(detailsView)
|
leftLayout.addView(detailsView)
|
||||||
}
|
}
|
||||||
|
|
@ -184,14 +190,14 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val editButton = MaterialButton(this).apply {
|
val editButton = MaterialButton(this).apply {
|
||||||
text = getString(R.string.btn_edit)
|
text = StringProvider.getString("btn_edit")
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
setTypeface(null, android.graphics.Typeface.BOLD)
|
setTypeface(null, android.graphics.Typeface.BOLD)
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.text_brown))
|
setTextColor(android.graphics.Color.parseColor("#5D4037"))
|
||||||
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
||||||
backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.brown_light_background))
|
backgroundTintList = ColorStateList.valueOf(android.graphics.Color.parseColor("#EFEBE9"))
|
||||||
strokeWidth = (1 * resources.displayMetrics.density).toInt()
|
strokeWidth = (1 * resources.displayMetrics.density).toInt()
|
||||||
strokeColor = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.text_brown))
|
strokeColor = ColorStateList.valueOf(android.graphics.Color.parseColor("#5D4037"))
|
||||||
layoutParams = buttonParams
|
layoutParams = buttonParams
|
||||||
insetTop = 0
|
insetTop = 0
|
||||||
insetBottom = 0
|
insetBottom = 0
|
||||||
|
|
@ -199,19 +205,19 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
minimumHeight = 0
|
minimumHeight = 0
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
val intent = Intent(this@GalleryActivity, AddAnimalProfileActivity::class.java)
|
val intent = Intent(this@GalleryActivity, CowSelectionActivity::class.java)
|
||||||
intent.putExtra("COW_NAME", cowName)
|
intent.putExtra("COW_NAME", cowName)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val rateButton = MaterialButton(this).apply {
|
val rateButton = MaterialButton(this).apply {
|
||||||
text = getString(R.string.btn_rate)
|
text = "Rate" // Add string if needed, skipping as per instruction to be concise unless requested
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
setTypeface(null, android.graphics.Typeface.BOLD)
|
setTypeface(null, android.graphics.Typeface.BOLD)
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.white))
|
setTextColor(android.graphics.Color.WHITE)
|
||||||
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
||||||
backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.earthy))
|
backgroundTintList = ColorStateList.valueOf(android.graphics.Color.parseColor("#6D4C41"))
|
||||||
layoutParams = buttonParams
|
layoutParams = buttonParams
|
||||||
insetTop = 0
|
insetTop = 0
|
||||||
insetBottom = 0
|
insetBottom = 0
|
||||||
|
|
@ -226,12 +232,12 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val deleteButton = MaterialButton(this).apply {
|
val deleteButton = MaterialButton(this).apply {
|
||||||
text = getString(R.string.btn_delete)
|
text = "Delete"
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
setTypeface(null, android.graphics.Typeface.BOLD)
|
setTypeface(null, android.graphics.Typeface.BOLD)
|
||||||
setTextColor(ContextCompat.getColor(context, R.color.white))
|
setTextColor(android.graphics.Color.WHITE)
|
||||||
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
||||||
backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.shutter_red))
|
backgroundTintList = ColorStateList.valueOf(android.graphics.Color.RED)
|
||||||
layoutParams = buttonParams
|
layoutParams = buttonParams
|
||||||
insetTop = 0
|
insetTop = 0
|
||||||
insetBottom = 0
|
insetBottom = 0
|
||||||
|
|
@ -287,21 +293,28 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
val parts = file.name.split("_")
|
val parts = file.name.split("_")
|
||||||
var orientation = ""
|
var orientation = ""
|
||||||
if (parts.size >= 3) {
|
if (parts.size >= 3) {
|
||||||
|
// format: cow_..._orientation_timestamp.jpg
|
||||||
|
// or cow_timestamp_orientation_...
|
||||||
|
// Let's guess. In CowSelectionActivity: ${name}_${orientation}_...
|
||||||
|
// name = cow_...
|
||||||
|
// so filename starts with name
|
||||||
|
|
||||||
// Let's just try to find a known orientation in the filename
|
// Let's just try to find a known orientation in the filename
|
||||||
val orientations = listOf("left", "right", "angle", "front", "back", "leftangle", "rightangle")
|
val orientations = listOf("left", "right", "angle", "front", "back", "leftangle", "rightangle")
|
||||||
orientation = orientations.find { file.name.contains("_${it}_") } ?: ""
|
orientation = orientations.find { file.name.contains("_${it}_") } ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
val label = when(orientation) {
|
val key = when(orientation) {
|
||||||
"front" -> getString(R.string.text_front_view)
|
"front" -> "text_front_view"
|
||||||
"back" -> getString(R.string.text_rear_view)
|
"back" -> "text_rear_view"
|
||||||
"left" -> getString(R.string.text_left_side)
|
"left" -> "text_left_side"
|
||||||
"right" -> getString(R.string.text_right_side)
|
"right" -> "text_right_side"
|
||||||
"angle" -> getString(R.string.text_angle_view)
|
"angle" -> "text_angle_view"
|
||||||
"leftangle" -> getString(R.string.text_left_angle)
|
"leftangle" -> "text_left_angle"
|
||||||
"rightangle" -> getString(R.string.text_right_angle)
|
"rightangle" -> "text_right_angle"
|
||||||
else -> orientation
|
else -> ""
|
||||||
}
|
}
|
||||||
|
val label = if (key.isNotEmpty()) StringProvider.getString(key) else orientation
|
||||||
|
|
||||||
labelView.text = label
|
labelView.text = label
|
||||||
|
|
||||||
|
|
@ -323,10 +336,10 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
parentDir.delete()
|
parentDir.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Toast.makeText(this@GalleryActivity, getString(R.string.toast_image_deleted), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@GalleryActivity, StringProvider.getString("toast_image_deleted"), Toast.LENGTH_SHORT).show()
|
||||||
refreshGallery()
|
refreshGallery()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this@GalleryActivity, getString(R.string.toast_error_deleting_image), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@GalleryActivity, StringProvider.getString("toast_error_deleting_image"), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,7 +389,7 @@ class GalleryActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(this, getString(R.string.toast_profile_deleted), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Cow profile deleted", Toast.LENGTH_SHORT).show()
|
||||||
refreshGallery()
|
refreshGallery()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.page
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
|
@ -21,23 +21,20 @@ import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.GravityCompat
|
import androidx.core.view.GravityCompat
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.drawerlayout.widget.DrawerLayout
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class HomeActivity : AppCompatActivity() {
|
class HomeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ALGORITHM_HAMMING = Constants.ALGORITHM_HAMMING
|
const val ALGORITHM_HAMMING = "Hamming Distance"
|
||||||
const val ALGORITHM_EUCLIDEAN = Constants.ALGORITHM_EUCLIDEAN
|
const val ALGORITHM_EUCLIDEAN = "Euclidean Distance"
|
||||||
const val ALGORITHM_JACCARD = Constants.ALGORITHM_JACCARD
|
const val ALGORITHM_JACCARD = "Jaccard Similarity"
|
||||||
private const val PERMISSION_REQUEST_CODE = 101
|
private const val PERMISSION_REQUEST_CODE = 101
|
||||||
const val PREF_COW_ILLUSTRATION_INDEX = Constants.PREF_COW_ILLUSTRATION_INDEX
|
private const val PREF_COW_ILLUSTRATION_INDEX = "COW_ILLUSTRATION_INDEX"
|
||||||
const val PREF_AUTO_CAPTURE = Constants.PREF_AUTO_CAPTURE
|
const val PREF_AUTO_CAPTURE = "AUTO_CAPTURE_ENABLED"
|
||||||
const val PREF_DEBUG_ENABLE = Constants.PREF_DEBUG_ENABLE
|
const val PREF_DEBUG_ENABLE = "AUTO_DEBUG_ENABLED"
|
||||||
const val PREF_MASK_DISPLAY = Constants.PREF_MASK_DISPLAY
|
const val PREF_MASK_DISPLAY = "MASK_DISPLAY_ENABLED"
|
||||||
var IS_RELEASE_BUILD = true // Set to true for release
|
var IS_RELEASE_BUILD = true // Set to true for release
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,6 +44,8 @@ class HomeActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_home)
|
setContentView(R.layout.activity_home)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
|
||||||
setupUI()
|
setupUI()
|
||||||
checkAndRequestPermissions()
|
checkAndRequestPermissions()
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +97,7 @@ class HomeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
// Language Spinner
|
// Language Spinner
|
||||||
val languageSpinner = findViewById<Spinner>(R.id.spinnerLanguage)
|
val languageSpinner = findViewById<Spinner>(R.id.spinnerLanguage)
|
||||||
val languages = listOf("English", "Hindi")
|
val languages = StringProvider.getLanguages()
|
||||||
val languageAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, languages)
|
val languageAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, languages)
|
||||||
languageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
languageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
languageSpinner.adapter = languageAdapter
|
languageSpinner.adapter = languageAdapter
|
||||||
|
|
@ -111,9 +110,11 @@ class HomeActivity : AppCompatActivity() {
|
||||||
val selectedLanguage = languages[position]
|
val selectedLanguage = languages[position]
|
||||||
val currentLang = prefs.getString("LANGUAGE", "English")
|
val currentLang = prefs.getString("LANGUAGE", "English")
|
||||||
|
|
||||||
|
// Only update and recreate if language actually changed
|
||||||
if (selectedLanguage != currentLang) {
|
if (selectedLanguage != currentLang) {
|
||||||
saveSettings()
|
saveSettings() // Save UI state so it's not lost
|
||||||
setLanguage(selectedLanguage)
|
StringProvider.setLanguage(selectedLanguage, this@HomeActivity)
|
||||||
|
// Post recreate to avoid WindowLeaked (allows spinner popup to close)
|
||||||
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
||||||
recreate()
|
recreate()
|
||||||
}
|
}
|
||||||
|
|
@ -122,17 +123,17 @@ class HomeActivity : AppCompatActivity() {
|
||||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set text from R.string
|
// Set text from StringProvider
|
||||||
findViewById<TextView>(R.id.tvTitle).text = getString(R.string.app_name)
|
findViewById<TextView>(R.id.tvTitle).text = StringProvider.getString("app_name")
|
||||||
findViewById<TextView>(R.id.tvSubtitle).text = getString(R.string.subtitle_home)
|
findViewById<TextView>(R.id.tvSubtitle).text = StringProvider.getString("subtitle_home")
|
||||||
findViewById<MaterialButton>(R.id.btnViewGallery).text = getString(R.string.btn_view_gallery)
|
findViewById<MaterialButton>(R.id.btnViewGallery).text = StringProvider.getString("btn_view_gallery")
|
||||||
findViewById<MaterialButton>(R.id.btnSelectCow).text = getString(R.string.btn_select_cow)
|
findViewById<MaterialButton>(R.id.btnSelectCow).text = StringProvider.getString("btn_select_cow")
|
||||||
findViewById<TextView>(R.id.tvAlgorithmLabel).text = getString(R.string.label_algorithm)
|
findViewById<TextView>(R.id.tvAlgorithmLabel).text = StringProvider.getString("label_algorithm")
|
||||||
findViewById<TextView>(R.id.tvThresholdLabel).text = getString(R.string.label_match_threshold)
|
findViewById<TextView>(R.id.tvThresholdLabel).text = StringProvider.getString("label_match_threshold")
|
||||||
|
|
||||||
// Cow Illustration and Logic
|
// Cow Illustration and Logic
|
||||||
val ivCowIllustration = findViewById<ImageView>(R.id.ivCowIllustration)
|
val ivCowIllustration = findViewById<ImageView>(R.id.ivCowIllustration)
|
||||||
val savedIndex = prefs.getInt(PREF_COW_ILLUSTRATION_INDEX, 4)
|
val savedIndex = prefs.getInt(PREF_COW_ILLUSTRATION_INDEX, 0)
|
||||||
setCowIllustration(ivCowIllustration, savedIndex)
|
setCowIllustration(ivCowIllustration, savedIndex)
|
||||||
|
|
||||||
ivCowIllustration.setOnClickListener { view ->
|
ivCowIllustration.setOnClickListener { view ->
|
||||||
|
|
@ -145,15 +146,18 @@ class HomeActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
findViewById<MaterialButton>(R.id.btnSelectCow).setOnClickListener {
|
findViewById<MaterialButton>(R.id.btnSelectCow).setOnClickListener {
|
||||||
|
// if (!IS_RELEASE_BUILD) { // This logic seemed wrong in previous thought, we want to start activity regardless?
|
||||||
|
// Ah, user said "dont show the settings panel". It doesn't mean disable "Add Cow".
|
||||||
|
// But previously I wrote logic to save settings before start.
|
||||||
if (!IS_RELEASE_BUILD) {
|
if (!IS_RELEASE_BUILD) {
|
||||||
saveSettings()
|
saveSettings()
|
||||||
}
|
}
|
||||||
startActivity(Intent(this, AddAnimalProfileActivity::class.java))
|
startActivity(Intent(this, CowSelectionActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto Capture Toggle
|
// Auto Capture Toggle
|
||||||
val switchAutoCapture = findViewById<SwitchMaterial>(R.id.switchAutoCapture)
|
val switchAutoCapture = findViewById<SwitchMaterial>(R.id.switchAutoCapture)
|
||||||
switchAutoCapture.text = getString(R.string.label_auto_capture)
|
switchAutoCapture.text = StringProvider.getString("label_auto_capture")
|
||||||
val autoCaptureEnabled = prefs.getBoolean(PREF_AUTO_CAPTURE, false)
|
val autoCaptureEnabled = prefs.getBoolean(PREF_AUTO_CAPTURE, false)
|
||||||
switchAutoCapture.isChecked = autoCaptureEnabled
|
switchAutoCapture.isChecked = autoCaptureEnabled
|
||||||
|
|
||||||
|
|
@ -162,11 +166,11 @@ class HomeActivity : AppCompatActivity() {
|
||||||
intArrayOf(-android.R.attr.state_checked)
|
intArrayOf(-android.R.attr.state_checked)
|
||||||
)
|
)
|
||||||
val thumbColors = intArrayOf(
|
val thumbColors = intArrayOf(
|
||||||
ContextCompat.getColor(this, R.color.earthy), // Dark Brown for On
|
Color.parseColor("#6D4C41"), // Dark Brown for On
|
||||||
Color.GRAY // Grey for Off
|
Color.GRAY // Grey for Off
|
||||||
)
|
)
|
||||||
val trackColors = intArrayOf(
|
val trackColors = intArrayOf(
|
||||||
ContextCompat.getColor(this, R.color.switch_track_brown), // Lighter Brown for On track
|
Color.parseColor("#8D6E63"), // Lighter Brown for On track
|
||||||
Color.LTGRAY // Light Grey for Off track
|
Color.LTGRAY // Light Grey for Off track
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -178,7 +182,7 @@ class HomeActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val switchEnableDebug = findViewById<SwitchMaterial>(R.id.switchEnableDebug)
|
val switchEnableDebug = findViewById<SwitchMaterial>(R.id.switchEnableDebug)
|
||||||
switchEnableDebug.text = getString(R.string.label_enable_debug)
|
switchEnableDebug.text = StringProvider.getString("label_enable_debug")
|
||||||
val debugEnabled = prefs.getBoolean(PREF_DEBUG_ENABLE, false)
|
val debugEnabled = prefs.getBoolean(PREF_DEBUG_ENABLE, false)
|
||||||
switchEnableDebug.isChecked = debugEnabled
|
switchEnableDebug.isChecked = debugEnabled
|
||||||
IS_RELEASE_BUILD = !debugEnabled
|
IS_RELEASE_BUILD = !debugEnabled
|
||||||
|
|
@ -198,15 +202,15 @@ class HomeActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val headerSettings = findViewById<TextView>(R.id.tvHeaderSettings)
|
val headerSettings = findViewById<TextView>(R.id.tvHeaderSettings)
|
||||||
if (headerSettings != null) headerSettings.text = getString(R.string.header_settings)
|
if (headerSettings != null) headerSettings.text = StringProvider.getString("header_settings")
|
||||||
|
|
||||||
// Algorithm Spinner
|
// Algorithm Spinner
|
||||||
val spinner = findViewById<Spinner>(R.id.spinnerAlgorithm)
|
val spinner = findViewById<Spinner>(R.id.spinnerAlgorithm)
|
||||||
|
|
||||||
val displayAlgorithms = listOf(
|
val displayAlgorithms = listOf(
|
||||||
getString(R.string.algo_hamming),
|
StringProvider.getString("algo_hamming"),
|
||||||
getString(R.string.algo_euclidean),
|
StringProvider.getString("algo_euclidean"),
|
||||||
getString(R.string.algo_jaccard)
|
StringProvider.getString("algo_jaccard")
|
||||||
)
|
)
|
||||||
|
|
||||||
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, displayAlgorithms)
|
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, displayAlgorithms)
|
||||||
|
|
@ -236,7 +240,7 @@ class HomeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
// Mask Display Toggle
|
// Mask Display Toggle
|
||||||
val switchMaskDisplay = findViewById<SwitchMaterial>(R.id.switchMaskDisplay)
|
val switchMaskDisplay = findViewById<SwitchMaterial>(R.id.switchMaskDisplay)
|
||||||
switchMaskDisplay.text = getString(R.string.label_mask_display)
|
switchMaskDisplay.text = StringProvider.getString("label_mask_display")
|
||||||
val maskDisplayEnabled = prefs.getBoolean(PREF_MASK_DISPLAY, false)
|
val maskDisplayEnabled = prefs.getBoolean(PREF_MASK_DISPLAY, false)
|
||||||
switchMaskDisplay.isChecked = maskDisplayEnabled
|
switchMaskDisplay.isChecked = maskDisplayEnabled
|
||||||
|
|
||||||
|
|
@ -251,29 +255,19 @@ class HomeActivity : AppCompatActivity() {
|
||||||
if (IS_RELEASE_BUILD) {
|
if (IS_RELEASE_BUILD) {
|
||||||
val settingsView = findViewById<CardView>(R.id.viewSettings)
|
val settingsView = findViewById<CardView>(R.id.viewSettings)
|
||||||
settingsView.visibility = View.GONE
|
settingsView.visibility = View.GONE
|
||||||
|
// Force defaults if needed, but logic above already sets defaults from prefs or code constants.
|
||||||
|
// If user wants to FORCE defaults every time release build runs:
|
||||||
|
/*
|
||||||
|
prefs.edit().putString("ALGORITHM", ALGORITHM_JACCARD).apply()
|
||||||
|
prefs.edit().putInt("THRESHOLD", 88).apply()
|
||||||
|
prefs.edit().putBoolean(PREF_MASK_DISPLAY, false).apply()
|
||||||
|
*/
|
||||||
|
// Leaving as is based on previous logic.
|
||||||
} else {
|
} else {
|
||||||
findViewById<CardView>(R.id.viewSettings).visibility = View.VISIBLE
|
findViewById<CardView>(R.id.viewSettings).visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setLanguage(language: String) {
|
|
||||||
val prefs = getSharedPreferences("AnimalRatingPrefs", MODE_PRIVATE)
|
|
||||||
prefs.edit().putString("LANGUAGE", language).apply()
|
|
||||||
|
|
||||||
val localeCode = when(language) {
|
|
||||||
"Hindi" -> "hi"
|
|
||||||
"Gujarati" -> "gu"
|
|
||||||
else -> "en"
|
|
||||||
}
|
|
||||||
|
|
||||||
val locale = Locale(localeCode)
|
|
||||||
Locale.setDefault(locale)
|
|
||||||
val config = resources.configuration
|
|
||||||
config.setLocale(locale)
|
|
||||||
createConfigurationContext(config)
|
|
||||||
resources.updateConfiguration(config, resources.displayMetrics)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showIllustrationPopup(anchor: View, imageView: ImageView) {
|
private fun showIllustrationPopup(anchor: View, imageView: ImageView) {
|
||||||
val popup = PopupMenu(this, anchor)
|
val popup = PopupMenu(this, anchor)
|
||||||
for (i in 0..4) {
|
for (i in 0..4) {
|
||||||
|
|
@ -324,7 +318,7 @@ class HomeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
// Save to preferences
|
// Save to preferences
|
||||||
val prefs = getSharedPreferences("AnimalRatingPrefs", MODE_PRIVATE)
|
val prefs = getSharedPreferences("AnimalRatingPrefs", MODE_PRIVATE)
|
||||||
val showMask = showSegmentationMask.isChecked
|
val showMask = prefs.getBoolean(PREF_MASK_DISPLAY, false)
|
||||||
prefs.edit().apply {
|
prefs.edit().apply {
|
||||||
putString("ALGORITHM", selectedAlgorithm)
|
putString("ALGORITHM", selectedAlgorithm)
|
||||||
putInt("THRESHOLD", threshold)
|
putInt("THRESHOLD", threshold)
|
||||||
|
|
@ -337,6 +331,6 @@ class HomeActivity : AppCompatActivity() {
|
||||||
private fun saveSettingsAndStart() {
|
private fun saveSettingsAndStart() {
|
||||||
if(!IS_RELEASE_BUILD)
|
if(!IS_RELEASE_BUILD)
|
||||||
saveSettings()
|
saveSettings()
|
||||||
startActivity(Intent(this, AddAnimalProfileActivity::class.java))
|
startActivity(Intent(this, CowSelectionActivity::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.page
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
|
@ -12,9 +12,6 @@ import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.toColorInt
|
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.storage.StorageUtils
|
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -43,6 +40,8 @@ class RatingActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_rating)
|
setContentView(R.layout.activity_rating)
|
||||||
|
|
||||||
|
StringProvider.initialize(this)
|
||||||
|
|
||||||
currentCowName = intent.getStringExtra("COW_NAME") ?: run {
|
currentCowName = intent.getStringExtra("COW_NAME") ?: run {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
|
|
@ -52,7 +51,7 @@ class RatingActivity : AppCompatActivity() {
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||||
toolbar.setNavigationOnClickListener { finish() }
|
toolbar.setNavigationOnClickListener { finish() }
|
||||||
findViewById<TextView>(R.id.tvToolbarTitle)?.text = getString(R.string.title_rate_cow)
|
findViewById<TextView>(R.id.tvToolbarTitle)?.text = StringProvider.getString("title_rate_cow")
|
||||||
|
|
||||||
setupUIStrings()
|
setupUIStrings()
|
||||||
loadCowDetails()
|
loadCowDetails()
|
||||||
|
|
@ -70,12 +69,12 @@ class RatingActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupUIStrings() {
|
private fun setupUIStrings() {
|
||||||
findViewById<TextView>(R.id.tvHeaderPhotos)?.text = getString(R.string.header_photos)
|
findViewById<TextView>(R.id.tvHeaderPhotos)?.text = StringProvider.getString("header_photos")
|
||||||
findViewById<TextView>(R.id.tvHeaderCowDetails)?.text = getString(R.string.header_cow_details)
|
findViewById<TextView>(R.id.tvHeaderCowDetails)?.text = StringProvider.getString("header_cow_details")
|
||||||
findViewById<TextView>(R.id.tvHeaderFeatureRatings)?.text = getString(R.string.header_feature_ratings)
|
findViewById<TextView>(R.id.tvHeaderFeatureRatings)?.text = StringProvider.getString("header_feature_ratings")
|
||||||
findViewById<TextInputLayout>(R.id.tilComments)?.hint = getString(R.string.hint_comments)
|
findViewById<TextInputLayout>(R.id.tilComments)?.hint = StringProvider.getString("hint_comments")
|
||||||
findViewById<MaterialButton>(R.id.btnSaveRating)?.text = getString(R.string.btn_save_rating)
|
findViewById<MaterialButton>(R.id.btnSaveRating)?.text = StringProvider.getString("btn_save_rating")
|
||||||
findViewById<MaterialButton>(R.id.btnCancelRating)?.text = getString(R.string.btn_cancel)
|
findViewById<MaterialButton>(R.id.btnCancelRating)?.text = StringProvider.getString("btn_cancel")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadCowDetails() {
|
private fun loadCowDetails() {
|
||||||
|
|
@ -88,18 +87,27 @@ class RatingActivity : AppCompatActivity() {
|
||||||
val record = lines.find { it.startsWith("$currentCowName,") }?.split(",") ?: return
|
val record = lines.find { it.startsWith("$currentCowName,") }?.split(",") ?: return
|
||||||
|
|
||||||
if (record.size >= 8) {
|
if (record.size >= 8) {
|
||||||
val displaySpecies = record[1]
|
// Translate values for display
|
||||||
val displayBreed = record[2]
|
val storedSpecies = record[1]
|
||||||
val displayStatus = record[6]
|
val speciesKey = StringProvider.getKeyForEnglishValue(storedSpecies)
|
||||||
|
val displaySpecies = if (speciesKey != null) StringProvider.getString(speciesKey) else storedSpecies
|
||||||
|
|
||||||
|
val storedBreed = record[2]
|
||||||
|
val breedKey = StringProvider.getKeyForEnglishValue(storedBreed)
|
||||||
|
val displayBreed = if (breedKey != null) StringProvider.getString(breedKey) else storedBreed
|
||||||
|
|
||||||
|
val storedStatus = record[6]
|
||||||
|
val statusKey = StringProvider.getKeyForEnglishValue(storedStatus)
|
||||||
|
val displayStatus = if (statusKey != null) StringProvider.getString(statusKey) else storedStatus
|
||||||
|
|
||||||
val infoText = StringBuilder()
|
val infoText = StringBuilder()
|
||||||
infoText.append("${getString(R.string.label_species)} $displaySpecies\n")
|
infoText.append("${StringProvider.getString("label_species")} $displaySpecies\n")
|
||||||
infoText.append("${getString(R.string.label_breed)} $displayBreed\n")
|
infoText.append("${StringProvider.getString("label_breed")} $displayBreed\n")
|
||||||
infoText.append("${getString(R.string.label_age)} ${record[3]} ${getString(R.string.unit_years)}\n")
|
infoText.append("${StringProvider.getString("label_age")} ${record[3]} ${StringProvider.getString("unit_years")}\n")
|
||||||
infoText.append("${getString(R.string.label_milk_yield)} ${record[4]} ${getString(R.string.unit_liters)}\n")
|
infoText.append("${StringProvider.getString("label_milk_yield")} ${record[4]} ${StringProvider.getString("unit_liters")}\n")
|
||||||
infoText.append("${getString(R.string.label_calving_no)} ${record[5]}\n")
|
infoText.append("${StringProvider.getString("label_calving_no")} ${record[5]}\n")
|
||||||
infoText.append("${getString(R.string.label_status)} $displayStatus\n")
|
infoText.append("${StringProvider.getString("label_status")} $displayStatus\n")
|
||||||
infoText.append("${getString(R.string.hint_description)}: ${record[7]}")
|
infoText.append("${StringProvider.getString("hint_description")}: ${record[7]}")
|
||||||
|
|
||||||
findViewById<TextView>(R.id.tvCowDetails).text = infoText.toString()
|
findViewById<TextView>(R.id.tvCowDetails).text = infoText.toString()
|
||||||
}
|
}
|
||||||
|
|
@ -153,20 +161,20 @@ class RatingActivity : AppCompatActivity() {
|
||||||
ratingsContainer = findViewById(R.id.ratingsContainer)
|
ratingsContainer = findViewById(R.id.ratingsContainer)
|
||||||
ratingsContainer.removeAllViews()
|
ratingsContainer.removeAllViews()
|
||||||
|
|
||||||
val textColor = ContextCompat.getColor(this, R.color.text_brown)
|
|
||||||
|
|
||||||
features.forEach { feature ->
|
features.forEach { feature ->
|
||||||
val featureView = layoutInflater.inflate(R.layout.item_feature_rating, ratingsContainer, false)
|
val featureView = layoutInflater.inflate(R.layout.item_feature_rating, ratingsContainer, false)
|
||||||
|
|
||||||
|
// Localize feature name
|
||||||
val key = "feature_" + feature.lowercase(Locale.ROOT).replace(" ", "_")
|
val key = "feature_" + feature.lowercase(Locale.ROOT).replace(" ", "_")
|
||||||
val resourceId = resources.getIdentifier(key, "string", packageName)
|
val displayName = StringProvider.getString(key)
|
||||||
val displayName = if (resourceId != 0) getString(resourceId) else feature
|
val finalName = if (displayName.isNotEmpty()) displayName else feature
|
||||||
|
|
||||||
featureView.findViewById<TextView>(R.id.tvFeatureName).text = displayName
|
featureView.findViewById<TextView>(R.id.tvFeatureName).text = finalName
|
||||||
|
|
||||||
val buttonContainer = featureView.findViewById<LinearLayout>(R.id.buttonContainer)
|
val buttonContainer = featureView.findViewById<LinearLayout>(R.id.buttonContainer)
|
||||||
val segmentViews = mutableListOf<TextView>()
|
val segmentViews = mutableListOf<TextView>()
|
||||||
|
|
||||||
|
// Create 9 segments
|
||||||
for (i in 1..9) {
|
for (i in 1..9) {
|
||||||
val tv = TextView(this)
|
val tv = TextView(this)
|
||||||
val params = LinearLayout.LayoutParams(
|
val params = LinearLayout.LayoutParams(
|
||||||
|
|
@ -177,16 +185,18 @@ class RatingActivity : AppCompatActivity() {
|
||||||
tv.layoutParams = params
|
tv.layoutParams = params
|
||||||
tv.text = i.toString()
|
tv.text = i.toString()
|
||||||
tv.gravity = Gravity.CENTER
|
tv.gravity = Gravity.CENTER
|
||||||
tv.setTextColor(textColor)
|
tv.setTextColor(ContextCompat.getColor(this, R.color.black))
|
||||||
tv.textSize = 14f
|
tv.textSize = 14f
|
||||||
tv.setBackgroundColor(Color.TRANSPARENT)
|
tv.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
|
||||||
tv.setOnClickListener {
|
tv.setOnClickListener {
|
||||||
val currentRating = ratingsMap[feature] ?: 0
|
val currentRating = ratingsMap[feature] ?: 0
|
||||||
if (currentRating == i) {
|
if (currentRating == i) {
|
||||||
|
// Clicked already selected -> Clear selection
|
||||||
ratingsMap[feature] = 0
|
ratingsMap[feature] = 0
|
||||||
updateSegmentSelection(segmentViews, 0)
|
updateSegmentSelection(segmentViews, 0)
|
||||||
} else {
|
} else {
|
||||||
|
// Select new rating
|
||||||
ratingsMap[feature] = i
|
ratingsMap[feature] = i
|
||||||
updateSegmentSelection(segmentViews, i)
|
updateSegmentSelection(segmentViews, i)
|
||||||
}
|
}
|
||||||
|
|
@ -202,9 +212,6 @@ class RatingActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSegmentSelection(segments: List<TextView>, selectedRating: Int) {
|
private fun updateSegmentSelection(segments: List<TextView>, selectedRating: Int) {
|
||||||
val selectedColor = ContextCompat.getColor(this, R.color.earthy)
|
|
||||||
val textColorUnselected = ContextCompat.getColor(this, R.color.text_brown)
|
|
||||||
|
|
||||||
segments.forEachIndexed { index, tv ->
|
segments.forEachIndexed { index, tv ->
|
||||||
val rating = index + 1
|
val rating = index + 1
|
||||||
if (rating == selectedRating) {
|
if (rating == selectedRating) {
|
||||||
|
|
@ -212,16 +219,18 @@ class RatingActivity : AppCompatActivity() {
|
||||||
|
|
||||||
val radius = (8 * resources.displayMetrics.density)
|
val radius = (8 * resources.displayMetrics.density)
|
||||||
val drawable = GradientDrawable()
|
val drawable = GradientDrawable()
|
||||||
drawable.setColor(selectedColor)
|
drawable.setColor(Color.parseColor("#6D4C41"))
|
||||||
|
|
||||||
when (rating) {
|
if (rating == 1) {
|
||||||
1 -> drawable.cornerRadii = floatArrayOf(radius, radius, 0f, 0f, 0f, 0f, radius, radius)
|
drawable.cornerRadii = floatArrayOf(radius, radius, 0f, 0f, 0f, 0f, radius, radius)
|
||||||
9 -> drawable.cornerRadii = floatArrayOf(0f, 0f, radius, radius, radius, radius, 0f, 0f)
|
} else if (rating == 9) {
|
||||||
else -> drawable.cornerRadius = 0f
|
drawable.cornerRadii = floatArrayOf(0f, 0f, radius, radius, radius, radius, 0f, 0f)
|
||||||
|
} else {
|
||||||
|
drawable.cornerRadius = 0f
|
||||||
}
|
}
|
||||||
tv.background = drawable
|
tv.background = drawable
|
||||||
} else {
|
} else {
|
||||||
tv.setTextColor(textColorUnselected)
|
tv.setTextColor(Color.parseColor("#5D4037"))
|
||||||
tv.background = null
|
tv.background = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -234,12 +243,16 @@ class RatingActivity : AppCompatActivity() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val lines = ratingsFile.readLines()
|
val lines = ratingsFile.readLines()
|
||||||
|
// Format: CowID,Comments,Feature1,Feature2,...
|
||||||
val record = lines.find { it.startsWith("$currentCowName,") }?.split(",") ?: return
|
val record = lines.find { it.startsWith("$currentCowName,") }?.split(",") ?: return
|
||||||
|
|
||||||
if (record.size >= 2) {
|
if (record.size >= 2) {
|
||||||
|
// Index 0: ID
|
||||||
|
// Index 1: Comments
|
||||||
val comments = record[1].replace(";", ",")
|
val comments = record[1].replace(";", ",")
|
||||||
findViewById<TextInputLayout>(R.id.tilComments).editText?.setText(comments)
|
findViewById<TextInputLayout>(R.id.tilComments).editText?.setText(comments)
|
||||||
|
|
||||||
|
// Ratings start from index 2
|
||||||
features.forEachIndexed { index, feature ->
|
features.forEachIndexed { index, feature ->
|
||||||
val ratingStr = record.getOrNull(index + 2)
|
val ratingStr = record.getOrNull(index + 2)
|
||||||
val rating = ratingStr?.toIntOrNull() ?: 0
|
val rating = ratingStr?.toIntOrNull() ?: 0
|
||||||
|
|
@ -247,6 +260,7 @@ class RatingActivity : AppCompatActivity() {
|
||||||
if (rating > 0) {
|
if (rating > 0) {
|
||||||
ratingsMap[feature] = rating
|
ratingsMap[feature] = rating
|
||||||
|
|
||||||
|
// Find view and update by index
|
||||||
val featureView = ratingsContainer.getChildAt(index)
|
val featureView = ratingsContainer.getChildAt(index)
|
||||||
if (featureView != null) {
|
if (featureView != null) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|
@ -268,14 +282,16 @@ class RatingActivity : AppCompatActivity() {
|
||||||
val docsFolder = StorageUtils.getDocumentsFolder()
|
val docsFolder = StorageUtils.getDocumentsFolder()
|
||||||
val ratingsFile = File(docsFolder, "cow_ratings.csv")
|
val ratingsFile = File(docsFolder, "cow_ratings.csv")
|
||||||
|
|
||||||
|
// Dynamically build header
|
||||||
val headerBuilder = StringBuilder("CowID,Comments")
|
val headerBuilder = StringBuilder("CowID,Comments")
|
||||||
features.forEach { headerBuilder.append(",$it") }
|
features.forEach { headerBuilder.append(",$it") }
|
||||||
val header = headerBuilder.toString()
|
val header = headerBuilder.toString()
|
||||||
|
|
||||||
|
// Build row
|
||||||
val rowBuilder = StringBuilder()
|
val rowBuilder = StringBuilder()
|
||||||
rowBuilder.append("$currentCowName,$comments")
|
rowBuilder.append("$currentCowName,$comments")
|
||||||
features.forEach { feature ->
|
features.forEach { feature ->
|
||||||
val rating = ratingsMap[feature] ?: 0
|
val rating = ratingsMap[feature] ?: 0 // Defaults to 0 if not selected
|
||||||
rowBuilder.append(",$rating")
|
rowBuilder.append(",$rating")
|
||||||
}
|
}
|
||||||
val newRow = rowBuilder.toString()
|
val newRow = rowBuilder.toString()
|
||||||
|
|
@ -285,6 +301,8 @@ class RatingActivity : AppCompatActivity() {
|
||||||
|
|
||||||
if (lines.isEmpty()) {
|
if (lines.isEmpty()) {
|
||||||
lines.add(header)
|
lines.add(header)
|
||||||
|
} else if (lines[0] != header) {
|
||||||
|
// Header mismatch handling
|
||||||
}
|
}
|
||||||
|
|
||||||
val existingIndex = lines.indexOfFirst { it.startsWith("$currentCowName,") }
|
val existingIndex = lines.indexOfFirst { it.startsWith("$currentCowName,") }
|
||||||
|
|
@ -301,10 +319,10 @@ class RatingActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(this, getString(R.string.toast_ratings_saved), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, StringProvider.getString("toast_ratings_saved"), Toast.LENGTH_SHORT).show()
|
||||||
finish()
|
finish()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(this, getString(R.string.toast_error_saving_ratings), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, StringProvider.getString("toast_error_saving_ratings"), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
package com.example.livingai.storage
|
package com.example.animalrating
|
||||||
|
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object StorageUtils {
|
object StorageUtils {
|
||||||
|
|
||||||
private const val ROOT_FOLDER_NAME = "com.LivingAI"
|
private const val ROOT_FOLDER_NAME = "com.AnimalRating"
|
||||||
|
|
||||||
private fun getBaseFolder(): File {
|
private fun getBaseFolder(): File {
|
||||||
|
// Changed to Android/media/com.AnimalRating as requested
|
||||||
val folder = File(Environment.getExternalStorageDirectory(), "Android/media/$ROOT_FOLDER_NAME")
|
val folder = File(Environment.getExternalStorageDirectory(), "Android/media/$ROOT_FOLDER_NAME")
|
||||||
if (!folder.exists()) {
|
if (!folder.exists()) {
|
||||||
folder.mkdirs()
|
folder.mkdirs()
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.example.animalrating
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
object StringProvider {
|
||||||
|
|
||||||
|
private var stringData: JSONObject? = null
|
||||||
|
private var currentLanguage = "English"
|
||||||
|
private const val DEFAULT_LANGUAGE = "English"
|
||||||
|
|
||||||
|
fun initialize(context: Context) {
|
||||||
|
if (stringData == null) {
|
||||||
|
try {
|
||||||
|
val inputStream: InputStream = context.resources.openRawResource(R.raw.strings)
|
||||||
|
val jsonString = inputStream.bufferedReader().use { it.readText() }
|
||||||
|
stringData = JSONObject(jsonString)
|
||||||
|
|
||||||
|
// Load saved language
|
||||||
|
val prefs = context.getSharedPreferences("AnimalRatingPrefs", Context.MODE_PRIVATE)
|
||||||
|
currentLanguage = prefs.getString("LANGUAGE", DEFAULT_LANGUAGE) ?: DEFAULT_LANGUAGE
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
// Handle error, maybe load default strings or log
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setLanguage(language: String, context: Context) {
|
||||||
|
currentLanguage = language
|
||||||
|
// Save selected language
|
||||||
|
val prefs = context.getSharedPreferences("AnimalRatingPrefs", Context.MODE_PRIVATE)
|
||||||
|
prefs.edit().putString("LANGUAGE", language).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLanguages(): List<String> {
|
||||||
|
return stringData?.keys()?.asSequence()?.toList() ?: listOf(DEFAULT_LANGUAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getString(key: String): String {
|
||||||
|
return getStringForLanguage(key, currentLanguage)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getStringEnglish(key: String): String {
|
||||||
|
return getStringForLanguage(key, DEFAULT_LANGUAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getStringForLanguage(key: String, language: String): String {
|
||||||
|
return try {
|
||||||
|
stringData?.getJSONObject(language)?.getString(key) ?: ""
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Fallback to English if key not found in current language
|
||||||
|
try {
|
||||||
|
if (language != DEFAULT_LANGUAGE) {
|
||||||
|
stringData?.getJSONObject(DEFAULT_LANGUAGE)?.getString(key) ?: ""
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
} catch (e2: Exception) {
|
||||||
|
"" // Return empty if not found anywhere
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getKeyForValue(value: String): String? {
|
||||||
|
// Helper to find the key for a given localized value in current language
|
||||||
|
// This is expensive, but useful if we need to reverse lookup
|
||||||
|
val langData = stringData?.optJSONObject(currentLanguage) ?: return null
|
||||||
|
val keys = langData.keys()
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
val key = keys.next()
|
||||||
|
if (langData.getString(key) == value) {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Also check English just in case it was stored as English
|
||||||
|
val englishData = stringData?.optJSONObject(DEFAULT_LANGUAGE) ?: return null
|
||||||
|
val engKeys = englishData.keys()
|
||||||
|
while (engKeys.hasNext()) {
|
||||||
|
val key = engKeys.next()
|
||||||
|
if (englishData.getString(key) == value) {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getKeyForEnglishValue(value: String): String? {
|
||||||
|
val englishData = stringData?.optJSONObject(DEFAULT_LANGUAGE) ?: return null
|
||||||
|
val engKeys = englishData.keys()
|
||||||
|
while (engKeys.hasNext()) {
|
||||||
|
val key = engKeys.next()
|
||||||
|
if (englishData.getString(key) == value) {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
package com.example.livingai.analysis
|
package com.example.animalrating.ml
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import androidx.camera.core.ImageAnalysis
|
import androidx.camera.core.ImageAnalysis
|
||||||
import androidx.camera.core.ImageProxy
|
import androidx.camera.core.ImageProxy
|
||||||
|
|
||||||
class Analyzer(
|
class CowAnalyzer(
|
||||||
private val listener: AnalysisListener
|
private val listener: CowListener
|
||||||
) : ImageAnalysis.Analyzer {
|
) : ImageAnalysis.Analyzer {
|
||||||
|
|
||||||
interface AnalysisListener {
|
interface CowListener {
|
||||||
fun onFrame(imageProxy: ImageProxy)
|
fun onFrame(imageProxy: ImageProxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.example.animalrating.ml
|
||||||
|
|
||||||
|
import android.graphics.*
|
||||||
|
import androidx.camera.core.ImageProxy
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert ImageProxy YUV_420_888 to Bitmap
|
||||||
|
*/
|
||||||
|
fun ImageProxy.toBitmap(): Bitmap {
|
||||||
|
val yBuffer = planes[0].buffer // Y
|
||||||
|
val uBuffer = planes[1].buffer // U
|
||||||
|
val vBuffer = planes[2].buffer // V
|
||||||
|
|
||||||
|
val ySize = yBuffer.remaining()
|
||||||
|
val uSize = uBuffer.remaining()
|
||||||
|
val vSize = vBuffer.remaining()
|
||||||
|
|
||||||
|
val nv21 = ByteArray(ySize + uSize + vSize)
|
||||||
|
|
||||||
|
// U and V are swapped, so we place V first then U
|
||||||
|
yBuffer.get(nv21, 0, ySize)
|
||||||
|
vBuffer.get(nv21, ySize, vSize)
|
||||||
|
uBuffer.get(nv21, ySize + vSize, uSize)
|
||||||
|
|
||||||
|
val yuvImage = YuvImage(
|
||||||
|
nv21,
|
||||||
|
ImageFormat.NV21,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
|
||||||
|
val out = ByteArrayOutputStream()
|
||||||
|
yuvImage.compressToJpeg(
|
||||||
|
Rect(0, 0, width, height),
|
||||||
|
90,
|
||||||
|
out
|
||||||
|
)
|
||||||
|
val jpegBytes = out.toByteArray()
|
||||||
|
|
||||||
|
return BitmapFactory.decodeByteArray(jpegBytes, 0, jpegBytes.size)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.example.animalrating.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.*
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
class MaskOverlay(context: Context, attrs: AttributeSet?) : View(context, attrs) {
|
||||||
|
|
||||||
|
private var maskBitmap: Bitmap? = null
|
||||||
|
private var matrix: Matrix = Matrix()
|
||||||
|
|
||||||
|
fun updateMask(bitmap: Bitmap?, transform: Matrix?) {
|
||||||
|
maskBitmap = bitmap
|
||||||
|
matrix = transform ?: Matrix()
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
val bmp = maskBitmap ?: return
|
||||||
|
canvas.drawBitmap(bmp, matrix, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.overlay
|
package com.example.animalrating.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.theme
|
package com.example.animalrating.ui.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.theme
|
package com.example.animalrating.ui.theme
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
|
@ -34,7 +34,7 @@ private val LightColorScheme = lightColorScheme(
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LivingAITheme(
|
fun AnimalRatingTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
// Dynamic color is available on Android 12+
|
// Dynamic color is available on Android 12+
|
||||||
dynamicColor: Boolean = true,
|
dynamicColor: Boolean = true,
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai.ui.theme
|
package com.example.animalrating.ui.theme
|
||||||
|
|
||||||
import androidx.compose.material3.Typography
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package com.example.livingai.analysis
|
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Matrix
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.camera.core.ExperimentalGetImage
|
|
||||||
import androidx.camera.core.ImageProxy
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import com.google.android.gms.tasks.Task
|
|
||||||
import com.google.android.gms.tasks.TaskCompletionSource
|
|
||||||
import com.google.mlkit.vision.common.InputImage
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Responsible for processing frames from the camera.
|
|
||||||
* It prepares the frame (e.g. orientation) and passes it to SegmentProcessor.
|
|
||||||
*/
|
|
||||||
class FrameProcessor {
|
|
||||||
fun prepareInputImage(imageProxy: ImageProxy, rotationDegrees: Int): InputImage? {
|
|
||||||
val mediaImage = imageProxy.image ?: return null
|
|
||||||
return InputImage.fromMediaImage(mediaImage, rotationDegrees)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
package com.example.livingai.analysis
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.util.Log
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class SavedMaskProcessor(private val context: Context) {
|
|
||||||
|
|
||||||
fun loadSavedMask(orientation: String): Bitmap? {
|
|
||||||
val filename = "${orientation}_mask.png"
|
|
||||||
val file = File(context.filesDir, filename)
|
|
||||||
var savedMaskBitmap: Bitmap? = null
|
|
||||||
|
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
val savedBitmap = BitmapFactory.decodeFile(file.absolutePath)
|
|
||||||
|
|
||||||
if (savedBitmap != null) {
|
|
||||||
//TODO: Added for debug can be removed safely
|
|
||||||
savedMaskBitmap = applyGreenColor(savedBitmap)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("SavedMaskProcessor", "Error loading saved mask", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return savedMaskBitmap
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Added for debug can be removed safely
|
|
||||||
private fun applyGreenColor(original: Bitmap): Bitmap {
|
|
||||||
val width = original.width
|
|
||||||
val height = original.height
|
|
||||||
val pixels = IntArray(width * height)
|
|
||||||
original.getPixels(pixels, 0, width, 0, 0, width, height)
|
|
||||||
for (i in pixels.indices) {
|
|
||||||
val alpha = (pixels[i] shr 24) and 0xff
|
|
||||||
if (alpha > 10) {
|
|
||||||
pixels[i] = Color.argb(alpha, 0, 255, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,265 +0,0 @@
|
||||||
package com.example.livingai.analysis
|
|
||||||
|
|
||||||
import android.content.res.Resources
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Matrix
|
|
||||||
import android.util.Log
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import com.google.android.gms.tasks.Task
|
|
||||||
import com.google.android.gms.tasks.TaskCompletionSource
|
|
||||||
import com.google.mlkit.vision.common.InputImage
|
|
||||||
import com.google.mlkit.vision.segmentation.subject.SubjectSegmentation
|
|
||||||
import com.google.mlkit.vision.segmentation.subject.SubjectSegmenterOptions
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
import kotlin.math.sqrt
|
|
||||||
|
|
||||||
data class SegmentationResult(
|
|
||||||
val mask: Bitmap?,
|
|
||||||
val isMatch: Boolean
|
|
||||||
)
|
|
||||||
|
|
||||||
class SegmentProcessor {
|
|
||||||
|
|
||||||
private val isProcessing = AtomicBoolean(false)
|
|
||||||
private val processingExecutor = Executors.newSingleThreadExecutor()
|
|
||||||
|
|
||||||
private val metrics = Resources.getSystem().displayMetrics
|
|
||||||
private val screenW = metrics.widthPixels
|
|
||||||
private val screenH = metrics.heightPixels
|
|
||||||
|
|
||||||
private val options = SubjectSegmenterOptions.Builder()
|
|
||||||
.enableMultipleSubjects(
|
|
||||||
SubjectSegmenterOptions.SubjectResultOptions.Builder()
|
|
||||||
.enableConfidenceMask()
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
private val segmenter = SubjectSegmentation.getClient(options)
|
|
||||||
|
|
||||||
fun process(
|
|
||||||
inputImage: InputImage,
|
|
||||||
savedMask: Bitmap?,
|
|
||||||
thresholdPercent: Int = 75,
|
|
||||||
algorithm: String = Constants.ALGORITHM_HAMMING
|
|
||||||
): Task<SegmentationResult> {
|
|
||||||
|
|
||||||
val tcs = TaskCompletionSource<SegmentationResult>()
|
|
||||||
|
|
||||||
if (!isProcessing.compareAndSet(false, true)) {
|
|
||||||
tcs.setResult(SegmentationResult(null, false))
|
|
||||||
return tcs.task
|
|
||||||
}
|
|
||||||
|
|
||||||
segmenter.process(inputImage)
|
|
||||||
.addOnSuccessListener(processingExecutor) { result ->
|
|
||||||
|
|
||||||
var bitmapMask: Bitmap? = null
|
|
||||||
val subject = result.subjects.firstOrNull()
|
|
||||||
val mask = subject?.confidenceMask
|
|
||||||
|
|
||||||
if (mask != null) {
|
|
||||||
|
|
||||||
val startX = subject.startX
|
|
||||||
val startY = subject.startY
|
|
||||||
val maskWidth = subject.width
|
|
||||||
val maskHeight = subject.height
|
|
||||||
|
|
||||||
val fullWidth = inputImage.width
|
|
||||||
val fullHeight = inputImage.height
|
|
||||||
|
|
||||||
if (mask.remaining() >= maskWidth * maskHeight) {
|
|
||||||
|
|
||||||
val colors = IntArray(fullWidth * fullHeight)
|
|
||||||
mask.rewind()
|
|
||||||
|
|
||||||
// Build full-resolution mask
|
|
||||||
for (y in 0 until maskHeight) {
|
|
||||||
for (x in 0 until maskWidth) {
|
|
||||||
if (mask.get() > 0.5f) {
|
|
||||||
val dx = startX + x
|
|
||||||
val dy = startY + y
|
|
||||||
if (dx < fullWidth && dy < fullHeight) {
|
|
||||||
colors[dy * fullWidth + dx] =
|
|
||||||
Color.argb(180, 255, 0, 255)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val rawBitmap = Bitmap.createBitmap(
|
|
||||||
colors, fullWidth, fullHeight, Bitmap.Config.ARGB_8888
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rotate to match screen orientation if needed (so segmentation mask is upright)
|
|
||||||
if (inputImage.rotationDegrees != 0) {
|
|
||||||
val matrix = Matrix()
|
|
||||||
matrix.postRotate(inputImage.rotationDegrees.toFloat())
|
|
||||||
bitmapMask = Bitmap.createBitmap(
|
|
||||||
rawBitmap, 0, 0, rawBitmap.width, rawBitmap.height, matrix, true
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
bitmapMask = rawBitmap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isMatch = false
|
|
||||||
|
|
||||||
if (bitmapMask != null && savedMask != null) {
|
|
||||||
//To consider all kinds of phones with aspect ratio and screen size
|
|
||||||
val (scaledSavedMask, scaledSegmentedMask) = scaleBothToScreenAndCrop(savedMask, bitmapMask)
|
|
||||||
|
|
||||||
isMatch = when (algorithm) {
|
|
||||||
Constants.ALGORITHM_EUCLIDEAN ->
|
|
||||||
calculateEuclideanDistance(scaledSavedMask, scaledSegmentedMask, thresholdPercent)
|
|
||||||
Constants.ALGORITHM_JACCARD ->
|
|
||||||
calculateJaccardSimilarity(scaledSavedMask, scaledSegmentedMask, thresholdPercent)
|
|
||||||
else ->
|
|
||||||
calculateHammingDistance(scaledSavedMask, scaledSegmentedMask, thresholdPercent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tcs.setResult(SegmentationResult(bitmapMask, isMatch))
|
|
||||||
}
|
|
||||||
.addOnFailureListener {
|
|
||||||
Log.e("SegmentProcessor", "Segmentation failed", it)
|
|
||||||
tcs.setException(it)
|
|
||||||
}
|
|
||||||
.addOnCompleteListener {
|
|
||||||
isProcessing.set(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return tcs.task
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calculateHammingDistance(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
|
||||||
if (mask1.width != mask2.width || mask1.height != mask2.height) return false
|
|
||||||
|
|
||||||
val width = mask1.width
|
|
||||||
val height = mask1.height
|
|
||||||
val p1 = IntArray(width * height)
|
|
||||||
val p2 = IntArray(width * height)
|
|
||||||
|
|
||||||
mask1.getPixels(p1, 0, width, 0, 0, width, height)
|
|
||||||
mask2.getPixels(p2, 0, width, 0, 0, width, height)
|
|
||||||
|
|
||||||
var distance = 0
|
|
||||||
|
|
||||||
for (i in p1.indices) {
|
|
||||||
val a = (p1[i] ushr 24) > 0
|
|
||||||
val b = (p2[i] ushr 24) > 0
|
|
||||||
if (a != b) distance++
|
|
||||||
}
|
|
||||||
|
|
||||||
val total = width * height
|
|
||||||
val allowed = total * (100 - thresholdPercent) / 100
|
|
||||||
|
|
||||||
return distance <= allowed
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calculateEuclideanDistance(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
|
||||||
if (mask1.width != mask2.width || mask1.height != mask2.height) return false
|
|
||||||
|
|
||||||
val width = mask1.width
|
|
||||||
val height = mask1.height
|
|
||||||
val p1 = IntArray(width * height)
|
|
||||||
val p2 = IntArray(width * height)
|
|
||||||
|
|
||||||
mask1.getPixels(p1, 0, width, 0, 0, width, height)
|
|
||||||
mask2.getPixels(p2, 0, width, 0, 0, width, height)
|
|
||||||
|
|
||||||
var sum = 0L
|
|
||||||
for (i in p1.indices) {
|
|
||||||
val v1 = if ((p1[i] ushr 24) > 0) 255 else 0
|
|
||||||
val v2 = if ((p2[i] ushr 24) > 0) 255 else 0
|
|
||||||
val diff = v1 - v2
|
|
||||||
sum += diff * diff
|
|
||||||
}
|
|
||||||
|
|
||||||
val dist = sqrt(sum.toDouble())
|
|
||||||
val max = sqrt((width * height).toDouble()) * 255.0
|
|
||||||
val allowed = max * (100 - thresholdPercent) / 100.0
|
|
||||||
|
|
||||||
return dist <= allowed
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calculateJaccardSimilarity(mask1: Bitmap, mask2: Bitmap, thresholdPercent: Int): Boolean {
|
|
||||||
if (mask1.width != mask2.width || mask1.height != mask2.height) return false
|
|
||||||
|
|
||||||
val width = mask1.width
|
|
||||||
val height = mask1.height
|
|
||||||
val p1 = IntArray(width * height)
|
|
||||||
val p2 = IntArray(width * height)
|
|
||||||
|
|
||||||
mask1.getPixels(p1, 0, width, 0, 0, width, height)
|
|
||||||
mask2.getPixels(p2, 0, width, 0, 0, width, height)
|
|
||||||
|
|
||||||
var intersection = 0
|
|
||||||
var union = 0
|
|
||||||
|
|
||||||
for (i in p1.indices) {
|
|
||||||
val a = ((p1[i] ushr 24) and 0xFF) > 0
|
|
||||||
val b = ((p2[i] ushr 24) and 0xFF) > 0
|
|
||||||
|
|
||||||
if (a && b) intersection++
|
|
||||||
if (a || b) union++
|
|
||||||
}
|
|
||||||
|
|
||||||
if (union == 0) return false
|
|
||||||
|
|
||||||
val score = (intersection.toDouble() / union.toDouble()) * 100.0
|
|
||||||
|
|
||||||
return score >= thresholdPercent
|
|
||||||
}
|
|
||||||
|
|
||||||
fun centerCrop(bmp: Bitmap, tw: Int, th: Int): Bitmap {
|
|
||||||
val offsetX = (bmp.width - tw) / 2
|
|
||||||
val offsetY = (bmp.height - th) / 2
|
|
||||||
return Bitmap.createBitmap(bmp, offsetX, offsetY, tw, th)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun scaleFitCenter(bmp: Bitmap, isFit: Boolean): Bitmap {
|
|
||||||
val w = bmp.width
|
|
||||||
val h = bmp.height
|
|
||||||
var scale: Float? = 0F
|
|
||||||
// scale to fit inside screen
|
|
||||||
if (isFit) {
|
|
||||||
scale = min(screenW.toFloat() / w, screenH.toFloat() / h)
|
|
||||||
} else {
|
|
||||||
scale = max(screenW.toFloat() / w, screenH.toFloat() / h)
|
|
||||||
}
|
|
||||||
val newW = (w * scale).toInt()
|
|
||||||
val newH = (h * scale).toInt()
|
|
||||||
|
|
||||||
return Bitmap.createScaledBitmap(bmp, newW, newH, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun scaleBothToScreenAndCrop(
|
|
||||||
savedMask: Bitmap,
|
|
||||||
segmentedMask: Bitmap
|
|
||||||
): Pair<Bitmap, Bitmap> {
|
|
||||||
|
|
||||||
val scaledA = scaleFitCenter(savedMask, true)
|
|
||||||
val scaledB = scaleFitCenter(segmentedMask, false)
|
|
||||||
|
|
||||||
val wA = scaledA.width
|
|
||||||
val hA = scaledA.height
|
|
||||||
val wB = scaledB.width
|
|
||||||
val hB = scaledB.height
|
|
||||||
|
|
||||||
val targetW = min(wA, wB)
|
|
||||||
val targetH = min(hA, hB)
|
|
||||||
|
|
||||||
val croppedA = centerCrop(scaledA, targetW, targetH)
|
|
||||||
val croppedB = centerCrop(scaledB, targetW, targetH)
|
|
||||||
|
|
||||||
return Pair(croppedA, croppedB)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
package com.example.livingai.camera
|
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.content.pm.ActivityInfo
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.camera.core.ExperimentalGetImage
|
|
||||||
import androidx.camera.core.ImageProxy
|
|
||||||
import androidx.core.content.edit
|
|
||||||
import androidx.core.graphics.toColorInt
|
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.analysis.Analyzer
|
|
||||||
import com.example.livingai.analysis.FrameProcessor
|
|
||||||
import com.example.livingai.analysis.SavedMaskProcessor
|
|
||||||
import com.example.livingai.analysis.SegmentProcessor
|
|
||||||
import com.example.livingai.commons.Constants
|
|
||||||
import com.example.livingai.ui.page.HomeActivity
|
|
||||||
import com.google.android.material.button.MaterialButton
|
|
||||||
|
|
||||||
class CameraActivity : AppCompatActivity(), Analyzer.AnalysisListener {
|
|
||||||
|
|
||||||
private lateinit var overlayManager: OverlayManager
|
|
||||||
private lateinit var cameraProcessor: CameraProcessor
|
|
||||||
private lateinit var frameProcessor: FrameProcessor
|
|
||||||
private lateinit var segmentProcessor: SegmentProcessor
|
|
||||||
private lateinit var savedMaskProcessor: SavedMaskProcessor
|
|
||||||
|
|
||||||
private var cowName: String? = null
|
|
||||||
private var orientation: String? = null
|
|
||||||
private var savedMaskBitmap: Bitmap? = null
|
|
||||||
private var matchThreshold = 75
|
|
||||||
private var algorithm = HomeActivity.ALGORITHM_HAMMING
|
|
||||||
private var isAutoCapture = true
|
|
||||||
private var isMaskDisplayEnabled = false
|
|
||||||
private var isPhotoTaken = false
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.activity_main)
|
|
||||||
|
|
||||||
cowName = intent.getStringExtra(Constants.COW_NAME)
|
|
||||||
orientation = intent.getStringExtra(Constants.ORIENTATION)
|
|
||||||
|
|
||||||
// Load settings
|
|
||||||
val prefs = getSharedPreferences("AnimalRatingPrefs", MODE_PRIVATE)
|
|
||||||
matchThreshold = prefs.getInt("THRESHOLD", 75)
|
|
||||||
algorithm = prefs.getString("ALGORITHM", HomeActivity.ALGORITHM_HAMMING) ?: HomeActivity.ALGORITHM_HAMMING
|
|
||||||
isAutoCapture = prefs.getBoolean(Constants.PREF_AUTO_CAPTURE, true)
|
|
||||||
isMaskDisplayEnabled = prefs.getBoolean(Constants.PREF_MASK_DISPLAY, false)
|
|
||||||
|
|
||||||
// Set orientation
|
|
||||||
if (orientation == "front" || orientation == "back") {
|
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
||||||
} else {
|
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize Managers and Processors
|
|
||||||
overlayManager = OverlayManager(
|
|
||||||
findViewById(R.id.silhouetteOverlay),
|
|
||||||
findViewById(R.id.segmentationOverlay),
|
|
||||||
findViewById(R.id.savedMaskOverlay)
|
|
||||||
)
|
|
||||||
|
|
||||||
cameraProcessor = CameraProcessor(this, findViewById(R.id.cameraPreview), this)
|
|
||||||
frameProcessor = FrameProcessor()
|
|
||||||
segmentProcessor = SegmentProcessor()
|
|
||||||
savedMaskProcessor = SavedMaskProcessor(this)
|
|
||||||
|
|
||||||
setupUI()
|
|
||||||
loadMasks()
|
|
||||||
|
|
||||||
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupUI() {
|
|
||||||
findViewById<MaterialButton>(R.id.btnExit).setOnClickListener { finish() }
|
|
||||||
|
|
||||||
val btnShutter = findViewById<MaterialButton>(R.id.btnShutter)
|
|
||||||
|
|
||||||
btnShutter.setOnClickListener {
|
|
||||||
cameraProcessor.takePhoto(
|
|
||||||
cowName, orientation,
|
|
||||||
intent.getIntExtra(Constants.SILHOUETTE_ID, 0),
|
|
||||||
intent.getStringExtra("RETAKE_IMAGE_PATH")
|
|
||||||
)
|
|
||||||
isPhotoTaken = true
|
|
||||||
}
|
|
||||||
|
|
||||||
val silhouetteId = intent.getIntExtra(Constants.SILHOUETTE_ID, 0)
|
|
||||||
overlayManager.setSilhouette(silhouetteId)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadMasks() {
|
|
||||||
savedMaskBitmap = savedMaskProcessor.loadSavedMask(orientation ?: "unknown")
|
|
||||||
overlayManager.showSavedMask(savedMaskBitmap, isMaskDisplayEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val requestPermissionLauncher =
|
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
|
||||||
if (granted) cameraProcessor.startCamera()
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExperimentalGetImage
|
|
||||||
override fun onFrame(imageProxy: ImageProxy) {
|
|
||||||
if (isPhotoTaken) {
|
|
||||||
imageProxy.close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
|
|
||||||
val inputImage = frameProcessor.prepareInputImage(imageProxy, rotationDegrees)
|
|
||||||
|
|
||||||
if (inputImage != null) {
|
|
||||||
segmentProcessor.process(inputImage, savedMaskBitmap, matchThreshold, algorithm)
|
|
||||||
.addOnSuccessListener { result ->
|
|
||||||
runOnUiThread {
|
|
||||||
overlayManager.showSegmentationMask(result.mask, isMaskDisplayEnabled)
|
|
||||||
}
|
|
||||||
if (isAutoCapture && result.isMatch && !isPhotoTaken) {
|
|
||||||
isPhotoTaken = true
|
|
||||||
cameraProcessor.takePhoto(
|
|
||||||
cowName, orientation,
|
|
||||||
intent.getIntExtra(Constants.SILHOUETTE_ID, 0),
|
|
||||||
intent.getStringExtra("RETAKE_IMAGE_PATH")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.addOnFailureListener { e ->
|
|
||||||
Log.e("CameraActivity", "Frame processing error", e)
|
|
||||||
}
|
|
||||||
.addOnCompleteListener {
|
|
||||||
imageProxy.close()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
imageProxy.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,177 +0,0 @@
|
||||||
package com.example.livingai.camera
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.graphics.Matrix
|
|
||||||
import android.util.Log
|
|
||||||
import android.util.Size
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.camera.core.AspectRatio
|
|
||||||
import androidx.camera.core.ImageAnalysis
|
|
||||||
import androidx.camera.core.ImageCapture
|
|
||||||
import androidx.camera.core.ImageCaptureException
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
|
||||||
import androidx.camera.view.PreviewView
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import com.example.livingai.R
|
|
||||||
import com.example.livingai.analysis.Analyzer
|
|
||||||
import com.example.livingai.storage.StorageUtils
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import kotlin.math.abs
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Responsible only for fetching camera frames and capturing images.
|
|
||||||
*/
|
|
||||||
class CameraProcessor(
|
|
||||||
private val context: Context,
|
|
||||||
private val previewView: PreviewView,
|
|
||||||
private val analysisListener: Analyzer.AnalysisListener
|
|
||||||
) {
|
|
||||||
|
|
||||||
private var imageCapture: ImageCapture? = null
|
|
||||||
private val cameraExecutor = Executors.newSingleThreadExecutor()
|
|
||||||
var analysisSize: Size? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
fun startCamera(onAnalysisSizeReady: (Int, Int) -> Unit = { _, _ -> }) {
|
|
||||||
val providerFuture = ProcessCameraProvider.getInstance(context)
|
|
||||||
|
|
||||||
providerFuture.addListener({
|
|
||||||
val cameraProvider = providerFuture.get()
|
|
||||||
|
|
||||||
val preview = androidx.camera.core.Preview.Builder().build()
|
|
||||||
preview.surfaceProvider = previewView.surfaceProvider
|
|
||||||
|
|
||||||
imageCapture = ImageCapture.Builder()
|
|
||||||
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val metrics = context.resources.displayMetrics
|
|
||||||
val screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)
|
|
||||||
|
|
||||||
val analyzer = ImageAnalysis.Builder()
|
|
||||||
.setTargetAspectRatio(screenAspectRatio)
|
|
||||||
.setBackpressureStrategy(
|
|
||||||
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
.also {
|
|
||||||
it.setAnalyzer(cameraExecutor, Analyzer(analysisListener))
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraProvider.unbindAll()
|
|
||||||
|
|
||||||
if (context is LifecycleOwner) {
|
|
||||||
cameraProvider.bindToLifecycle(
|
|
||||||
context,
|
|
||||||
androidx.camera.core.CameraSelector.DEFAULT_BACK_CAMERA,
|
|
||||||
preview,
|
|
||||||
imageCapture,
|
|
||||||
analyzer
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get analysis resolution
|
|
||||||
analyzer.resolutionInfo?.resolution?.let { size ->
|
|
||||||
analysisSize = size
|
|
||||||
onAnalysisSizeReady(size.width, size.height)
|
|
||||||
} ?: run {
|
|
||||||
// Fallback: if resolution info is not available immediately
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, ContextCompat.getMainExecutor(context))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun aspectRatio(width: Int, height: Int): Int {
|
|
||||||
val previewRatio = max(width, height).toDouble() / min(width, height)
|
|
||||||
if (abs(previewRatio - 4.0 / 3.0) <= abs(previewRatio - 16.0 / 9.0)) {
|
|
||||||
return AspectRatio.RATIO_4_3
|
|
||||||
}
|
|
||||||
return AspectRatio.RATIO_16_9
|
|
||||||
}
|
|
||||||
|
|
||||||
fun takePhoto(cowName: String?, orientation: String?, silhouetteId: Int, retakePath: String? = null) {
|
|
||||||
val imageCapture = imageCapture ?: return
|
|
||||||
|
|
||||||
val name = cowName ?: "unknown"
|
|
||||||
val side = orientation ?: "unknown"
|
|
||||||
|
|
||||||
// Find current count for this cow and orientation
|
|
||||||
val cowFolder = StorageUtils.getCowImageFolder(name)
|
|
||||||
|
|
||||||
val existingFiles = cowFolder.listFiles { _, fname ->
|
|
||||||
fname.startsWith("${name}_${side}_") && fname.endsWith(".jpg")
|
|
||||||
}
|
|
||||||
val count = (existingFiles?.size ?: 0) + 1
|
|
||||||
|
|
||||||
if (!cowFolder.exists()) {
|
|
||||||
cowFolder.mkdirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
val filename = "${name}_${side}_${count}.jpg"
|
|
||||||
val file = File(cowFolder, filename)
|
|
||||||
|
|
||||||
val outputOptions = ImageCapture.OutputFileOptions.Builder(file).build()
|
|
||||||
|
|
||||||
imageCapture.takePicture(
|
|
||||||
outputOptions,
|
|
||||||
ContextCompat.getMainExecutor(context),
|
|
||||||
object : ImageCapture.OnImageSavedCallback {
|
|
||||||
override fun onError(exc: ImageCaptureException) {
|
|
||||||
Log.e("CameraProcessor", "Photo capture failed: ${exc.message}", exc)
|
|
||||||
Toast.makeText(context, context.getString(R.string.toast_capture_failed), Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onImageSaved(output: ImageCapture.OutputFileResults) {
|
|
||||||
try {
|
|
||||||
val bitmap = BitmapFactory.decodeFile(file.absolutePath)
|
|
||||||
val matrix = Matrix()
|
|
||||||
|
|
||||||
val rotation = if (orientation == "front" || orientation == "back") 90f else 0f
|
|
||||||
|
|
||||||
if (rotation != 0f) {
|
|
||||||
matrix.postRotate(rotation)
|
|
||||||
val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
|
||||||
FileOutputStream(file).use { out ->
|
|
||||||
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!retakePath.isNullOrEmpty()) {
|
|
||||||
val oldFile = File(retakePath)
|
|
||||||
if (oldFile.exists()) {
|
|
||||||
oldFile.delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val msg = "${context.getString(R.string.toast_saved_as)} $filename"
|
|
||||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
|
|
||||||
|
|
||||||
// Navigate to FullScreenImageActivity
|
|
||||||
val intent = android.content.Intent(context, com.example.livingai.ui.page.FullScreenImageActivity::class.java)
|
|
||||||
intent.putExtra("IMAGE_PATH", file.absolutePath)
|
|
||||||
intent.putExtra("ALLOW_RETAKE", true)
|
|
||||||
intent.putExtra("COW_NAME", cowName)
|
|
||||||
intent.putExtra("ORIENTATION", orientation)
|
|
||||||
intent.putExtra("SILHOUETTE_ID", silhouetteId)
|
|
||||||
context.startActivity(intent)
|
|
||||||
|
|
||||||
if (context is android.app.Activity) {
|
|
||||||
context.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("CameraProcessor", "Error saving image", e)
|
|
||||||
Toast.makeText(context, context.getString(R.string.toast_error_saving_image), Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package com.example.livingai.camera
|
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.ImageView
|
|
||||||
import com.example.livingai.ui.overlay.MaskOverlay
|
|
||||||
import com.example.livingai.ui.overlay.SilhouetteOverlay
|
|
||||||
|
|
||||||
class OverlayManager(
|
|
||||||
private val silhouetteOverlay: SilhouetteOverlay,
|
|
||||||
private val segmentationOverlay: MaskOverlay,
|
|
||||||
private val savedMaskOverlay: MaskOverlay
|
|
||||||
) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
// Configure scaling types
|
|
||||||
segmentationOverlay.scaleType = MaskOverlay.ScaleType.CENTER_CROP
|
|
||||||
savedMaskOverlay.scaleType = MaskOverlay.ScaleType.FIT_CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setSilhouette(silhouetteId: Int) {
|
|
||||||
silhouetteOverlay.setSilhouette(silhouetteId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showSegmentationMask(mask: Bitmap?, isEnabled: Boolean) {
|
|
||||||
segmentationOverlay.updateMask(if (isEnabled) mask else null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showSavedMask(mask: Bitmap?, isEnabled: Boolean) {
|
|
||||||
savedMaskOverlay.updateMask(if (isEnabled) mask else null)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package com.example.livingai.commons
|
|
||||||
|
|
||||||
import android.provider.Settings.Global.getString
|
|
||||||
|
|
||||||
object Constants {
|
|
||||||
const val ALGORITHM_HAMMING = "Hamming Distance"
|
|
||||||
const val ALGORITHM_EUCLIDEAN = "Euclidean Distance"
|
|
||||||
const val ALGORITHM_JACCARD = "Jaccard Similarity"
|
|
||||||
|
|
||||||
const val PREF_AUTO_CAPTURE = "AUTO_CAPTURE_ENABLED"
|
|
||||||
const val PREF_MASK_DISPLAY = "MASK_DISPLAY_ENABLED"
|
|
||||||
const val PREF_DEBUG_ENABLE = "AUTO_DEBUG_ENABLED"
|
|
||||||
const val PREF_COW_ILLUSTRATION_INDEX = "COW_ILLUSTRATION_INDEX"
|
|
||||||
|
|
||||||
const val COW_NAME = "COW_NAME"
|
|
||||||
const val ORIENTATION = "ORIENTATION"
|
|
||||||
const val SILHOUETTE_ID = "SILHOUETTE_ID"
|
|
||||||
val ORIENTATION_NAMES = listOf("left", "right", "angle", "front", "back", "leftangle", "rightangle")
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
package com.example.livingai.ui.overlay
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.Canvas
|
|
||||||
import android.graphics.Matrix
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.View
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
class MaskOverlay(context: Context, attrs: AttributeSet?) : View(context, attrs) {
|
|
||||||
|
|
||||||
enum class ScaleType {
|
|
||||||
CENTER_CROP,
|
|
||||||
FIT_CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
private var maskBitmap: Bitmap? = null
|
|
||||||
private val matrix = Matrix()
|
|
||||||
var scaleType: ScaleType = ScaleType.CENTER_CROP
|
|
||||||
|
|
||||||
fun updateMask(bitmap: Bitmap?) {
|
|
||||||
maskBitmap = bitmap
|
|
||||||
invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
|
||||||
super.onDraw(canvas)
|
|
||||||
|
|
||||||
val bmp = maskBitmap ?: return
|
|
||||||
if (bmp.width == 0 || bmp.height == 0) return
|
|
||||||
|
|
||||||
val viewWidth = width.toFloat()
|
|
||||||
val viewHeight = height.toFloat()
|
|
||||||
val bmpWidth = bmp.width.toFloat()
|
|
||||||
val bmpHeight = bmp.height.toFloat()
|
|
||||||
|
|
||||||
matrix.reset()
|
|
||||||
|
|
||||||
val scaleX = viewWidth / bmpWidth
|
|
||||||
val scaleY = viewHeight / bmpHeight
|
|
||||||
|
|
||||||
val scale = if (scaleType == ScaleType.FIT_CENTER) {
|
|
||||||
min(scaleX, scaleY)
|
|
||||||
} else {
|
|
||||||
max(scaleX, scaleY)
|
|
||||||
}
|
|
||||||
|
|
||||||
val scaledWidth = bmpWidth * scale
|
|
||||||
val scaledHeight = bmpHeight * scale
|
|
||||||
|
|
||||||
val dx = (viewWidth - scaledWidth) / 2f
|
|
||||||
val dy = (viewHeight - scaledHeight) / 2f
|
|
||||||
|
|
||||||
matrix.postScale(scale, scale)
|
|
||||||
matrix.postTranslate(dx, dy)
|
|
||||||
|
|
||||||
canvas.drawBitmap(bmp, matrix, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -303,7 +303,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnfront"
|
android:id="@+id/btnFront"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -336,7 +336,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnback"
|
android:id="@+id/btnBack"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -369,7 +369,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnleft"
|
android:id="@+id/btnLeft"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -402,7 +402,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnright"
|
android:id="@+id/btnRight"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -435,7 +435,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnleftangle"
|
android:id="@+id/btnLeftAngle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -468,7 +468,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnrightangle"
|
android:id="@+id/btnRightAngle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -501,7 +501,7 @@
|
||||||
app:cardCornerRadius="8dp"
|
app:cardCornerRadius="8dp"
|
||||||
app:cardElevation="2dp">
|
app:cardElevation="2dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/btnangle"
|
android:id="@+id/btnTop"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -548,9 +548,8 @@
|
||||||
android:text="Save Profile"
|
android:text="Save Profile"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/white"
|
|
||||||
app:cornerRadius="12dp"
|
app:cornerRadius="12dp"
|
||||||
app:backgroundTint="@color/earthy"
|
app:backgroundTint="@color/text_tertiary"
|
||||||
android:layout_marginEnd="8dp"/>
|
android:layout_marginEnd="8dp"/>
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/black">
|
android:background="#000000">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/fullScreenImageView"
|
android:id="@+id/fullScreenImageView"
|
||||||
|
|
@ -23,10 +23,9 @@
|
||||||
android:src="@drawable/ic_round_back_button"
|
android:src="@drawable/ic_round_back_button"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerInside"
|
||||||
android:contentDescription="Back"
|
android:contentDescription="Back" />
|
||||||
app:tint="@color/white"/>
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<Button
|
||||||
android:id="@+id/btnRetake"
|
android:id="@+id/btnRetake"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -34,9 +33,6 @@
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginBottom="32dp"
|
android:layout_marginBottom="32dp"
|
||||||
android:text="Retake"
|
android:text="Retake"
|
||||||
android:visibility="gone"
|
android:visibility="gone" />
|
||||||
android:textColor="@color/white"
|
|
||||||
app:backgroundTint="@color/earthy"
|
|
||||||
app:cornerRadius="12dp"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
@ -48,8 +48,7 @@
|
||||||
app:boxStrokeWidth="0dp"
|
app:boxStrokeWidth="0dp"
|
||||||
app:startIconDrawable="@android:drawable/ic_menu_search"
|
app:startIconDrawable="@android:drawable/ic_menu_search"
|
||||||
app:startIconTint="@color/text_secondary"
|
app:startIconTint="@color/text_secondary"
|
||||||
android:hint="Search profiles..."
|
android:hint="Search profiles...">
|
||||||
android:textColorHint="@color/text_secondary">
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
@ -98,6 +97,6 @@
|
||||||
android:layout_margin="24dp"
|
android:layout_margin="24dp"
|
||||||
app:srcCompat="@android:drawable/ic_input_add"
|
app:srcCompat="@android:drawable/ic_input_add"
|
||||||
app:tint="@color/white"
|
app:tint="@color/white"
|
||||||
app:backgroundTint="@color/earthy"/>
|
app:backgroundTint="@color/text_tertiary"/>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
@ -33,8 +33,7 @@
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:src="@android:drawable/ic_menu_sort_by_size"
|
android:src="@android:drawable/ic_menu_sort_by_size"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:backgroundTint="@color/icon_tint_primary"
|
android:contentDescription="Menu"
|
||||||
android:contentDescription="Settings"
|
|
||||||
app:tint="@color/icon_tint_primary"/>
|
app:tint="@color/icon_tint_primary"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
@ -94,13 +93,11 @@
|
||||||
android:text="Add New Cow Profile"
|
android:text="Add New Cow Profile"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/white"
|
|
||||||
app:cornerRadius="16dp"
|
app:cornerRadius="16dp"
|
||||||
app:backgroundTint="@color/earthy"
|
app:backgroundTint="@color/text_tertiary"
|
||||||
app:icon="@android:drawable/ic_input_add"
|
app:icon="@android:drawable/ic_input_add"
|
||||||
app:iconGravity="textStart"
|
app:iconGravity="textStart"
|
||||||
app:iconPadding="12dp"
|
app:iconPadding="12dp"
|
||||||
app:iconTint="@color/white"
|
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:elevation="4dp"/>
|
android:elevation="4dp"/>
|
||||||
|
|
||||||
|
|
@ -144,7 +141,7 @@
|
||||||
android:id="@+id/tvHeaderSettings"
|
android:id="@+id/tvHeaderSettings"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Debug Configs"
|
android:text="Settings"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_primary"
|
||||||
|
|
@ -164,14 +161,12 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/bg_spinner_rounded"
|
android:background="@drawable/bg_spinner_rounded"
|
||||||
android:backgroundTint="@color/input_background"
|
|
||||||
android:padding="4dp"
|
android:padding="4dp"
|
||||||
android:layout_marginBottom="20dp">
|
android:layout_marginBottom="20dp">
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinnerAlgorithm"
|
android:id="@+id/spinnerAlgorithm"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"/>
|
||||||
android:backgroundTint="@color/text_primary"/>
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<!-- Threshold Slider -->
|
<!-- Threshold Slider -->
|
||||||
|
|
@ -205,8 +200,8 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:max="100"
|
android:max="100"
|
||||||
android:progressTint="@color/earthy"
|
android:progressTint="@color/text_tertiary"
|
||||||
android:thumbTint="@color/earthy"
|
android:thumbTint="@color/text_tertiary"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
<!-- Mask Display Toggle -->
|
<!-- Mask Display Toggle -->
|
||||||
|
|
@ -215,9 +210,9 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Show Segmentation Mask"
|
android:text="Show Segmentation Mask"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
app:thumbTint="@color/earthy"
|
app:thumbTint="@color/text_tertiary"
|
||||||
app:trackTint="@color/input_background"/>
|
app:trackTint="@color/input_background"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -261,7 +256,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:background="@drawable/bg_spinner_rounded"
|
android:background="@drawable/bg_spinner_rounded"
|
||||||
android:backgroundTint="@color/input_background"
|
|
||||||
android:layout_marginBottom="24dp"/>
|
android:layout_marginBottom="24dp"/>
|
||||||
|
|
||||||
<!-- Auto Capture Toggle -->
|
<!-- Auto Capture Toggle -->
|
||||||
|
|
@ -270,9 +264,9 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Auto Capture"
|
android:text="Auto Capture"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
app:thumbTint="@color/earthy"
|
app:thumbTint="@color/text_tertiary"
|
||||||
app:trackTint="@color/input_background"
|
app:trackTint="@color/input_background"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
|
@ -282,9 +276,9 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Enable Debug"
|
android:text="Enable Debug"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
app:thumbTint="@color/earthy"
|
app:thumbTint="@color/text_tertiary"
|
||||||
app:trackTint="@color/input_background"
|
app:trackTint="@color/input_background"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,35 +8,28 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<com.example.livingai.ui.overlay.SilhouetteOverlay
|
<com.example.animalrating.ui.SilhouetteOverlay
|
||||||
android:id="@+id/silhouetteOverlay"
|
android:id="@+id/silhouetteOverlay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<com.example.livingai.ui.overlay.MaskOverlay
|
<!-- ImageView to display the saved mask (Green)-->
|
||||||
|
<ImageView
|
||||||
android:id="@+id/savedMaskOverlay"
|
android:id="@+id/savedMaskOverlay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
android:elevation="5dp"/>
|
android:elevation="5dp"/>
|
||||||
|
|
||||||
<com.example.livingai.ui.overlay.MaskOverlay
|
<!-- ImageView to display the segmentation mask (Live)-->
|
||||||
|
<ImageView
|
||||||
android:id="@+id/segmentationOverlay"
|
android:id="@+id/segmentationOverlay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:alpha="0.9"
|
||||||
android:elevation="10dp"/>
|
android:elevation="10dp"/>
|
||||||
|
|
||||||
<com.example.livingai.ui.overlay.MaskOverlay
|
|
||||||
android:id="@+id/overlayBlue"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:elevation="11dp"/>
|
|
||||||
|
|
||||||
<com.example.livingai.ui.overlay.MaskOverlay
|
|
||||||
android:id="@+id/overlayGreen"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:elevation="12dp"/>
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btnExit"
|
android:id="@+id/btnExit"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
|
|
@ -46,8 +39,30 @@
|
||||||
style="@style/Widget.MaterialComponents.Button.Icon"
|
style="@style/Widget.MaterialComponents.Button.Icon"
|
||||||
app:icon="@drawable/ic_back_arrow"
|
app:icon="@drawable/ic_back_arrow"
|
||||||
app:iconSize="24dp"
|
app:iconSize="24dp"
|
||||||
app:iconTint="@color/white"
|
app:iconTint="#FFFFFF"
|
||||||
app:backgroundTint="@color/camera_overlay_button"
|
app:backgroundTint="#80000000"
|
||||||
|
app:cornerRadius="24dp"
|
||||||
|
android:padding="0dp"
|
||||||
|
android:insetLeft="0dp"
|
||||||
|
android:insetTop="0dp"
|
||||||
|
android:insetRight="0dp"
|
||||||
|
android:insetBottom="0dp"
|
||||||
|
app:iconGravity="textStart"
|
||||||
|
app:iconPadding="0dp"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
<!-- Toggle Auto/Manual Capture Button -->
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btnToggleCaptureMode"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
style="@style/Widget.MaterialComponents.Button.Icon"
|
||||||
|
app:icon="@android:drawable/ic_menu_camera"
|
||||||
|
app:iconSize="24dp"
|
||||||
|
app:iconTint="#FFFFFF"
|
||||||
|
app:backgroundTint="#80000000"
|
||||||
app:cornerRadius="24dp"
|
app:cornerRadius="24dp"
|
||||||
android:padding="0dp"
|
android:padding="0dp"
|
||||||
android:insetLeft="0dp"
|
android:insetLeft="0dp"
|
||||||
|
|
@ -68,10 +83,10 @@
|
||||||
style="@style/Widget.MaterialComponents.Button.Icon"
|
style="@style/Widget.MaterialComponents.Button.Icon"
|
||||||
app:icon="@android:drawable/ic_menu_camera"
|
app:icon="@android:drawable/ic_menu_camera"
|
||||||
app:iconSize="40dp"
|
app:iconSize="40dp"
|
||||||
app:iconTint="@color/white"
|
app:iconTint="#FFFFFF"
|
||||||
app:backgroundTint="@color/shutter_red"
|
app:backgroundTint="#D32F2F"
|
||||||
app:cornerRadius="36dp"
|
app:cornerRadius="36dp"
|
||||||
app:strokeColor="@color/white"
|
app:strokeColor="#FFFFFF"
|
||||||
app:strokeWidth="4dp"
|
app:strokeWidth="4dp"
|
||||||
android:padding="0dp"
|
android:padding="0dp"
|
||||||
android:insetLeft="0dp"
|
android:insetLeft="0dp"
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,7 @@
|
||||||
app:boxCornerRadiusBottomStart="12dp"
|
app:boxCornerRadiusBottomStart="12dp"
|
||||||
app:boxCornerRadiusBottomEnd="12dp"
|
app:boxCornerRadiusBottomEnd="12dp"
|
||||||
app:boxStrokeColor="@color/text_tertiary"
|
app:boxStrokeColor="@color/text_tertiary"
|
||||||
android:hint="Comments"
|
android:hint="Comments">
|
||||||
android:textColorHint="@color/text_secondary">
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
@ -134,10 +133,8 @@
|
||||||
android:text="Save Rating"
|
android:text="Save Rating"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/white"
|
|
||||||
app:cornerRadius="12dp"
|
app:cornerRadius="12dp"
|
||||||
app:backgroundTint="@color/earthy"
|
app:backgroundTint="@color/text_tertiary"/>
|
||||||
android:layout_marginBottom="16dp"/>
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btnCancelRating"
|
android:id="@+id/btnCancelRating"
|
||||||
|
|
@ -146,11 +143,8 @@
|
||||||
android:text="Cancel"
|
android:text="Cancel"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/icon_tint_primary"
|
|
||||||
app:cornerRadius="12dp"
|
app:cornerRadius="12dp"
|
||||||
app:backgroundTint="@color/input_background"
|
app:backgroundTint="@color/text_tertiary"/>
|
||||||
app:strokeColor="@color/icon_tint_primary"
|
|
||||||
app:strokeWidth="1dp"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:background="@drawable/bg_rating_segment"
|
android:background="@drawable/bg_rating_segment"
|
||||||
android:backgroundTint="@color/input_background"
|
|
||||||
android:weightSum="9"
|
android:weightSum="9"
|
||||||
android:showDividers="middle"
|
android:showDividers="middle"
|
||||||
android:divider="@drawable/divider_rating_segment"/>
|
android:divider="@drawable/divider_rating_segment"/>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
android:background="@color/text_tertiary"/>
|
android:background="#E0E0E0"/>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
|
@ -25,8 +25,8 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:background="@color/camera_overlay_button"
|
android:background="#80000000"
|
||||||
android:textColor="@color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="10sp"
|
||||||
android:padding="2dp"
|
android:padding="2dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
|
@ -41,8 +41,8 @@
|
||||||
android:layout_margin="4dp"
|
android:layout_margin="4dp"
|
||||||
app:icon="@android:drawable/ic_delete"
|
app:icon="@android:drawable/ic_delete"
|
||||||
app:iconSize="14dp"
|
app:iconSize="14dp"
|
||||||
app:iconTint="@color/white"
|
app:iconTint="#FFFFFF"
|
||||||
android:backgroundTint="@color/shutter_red"
|
android:backgroundTint="#C62828"
|
||||||
app:cornerRadius="12dp"
|
app:cornerRadius="12dp"
|
||||||
android:padding="0dp"
|
android:padding="0dp"
|
||||||
android:insetLeft="0dp"
|
android:insetLeft="0dp"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,212 @@
|
||||||
|
{
|
||||||
|
"English": {
|
||||||
|
"app_name": "Animal Rating",
|
||||||
|
"title_home": "Animal Rating",
|
||||||
|
"title_gallery": "Saved Cow Profiles",
|
||||||
|
"title_add_cow_details": "Add Cow Details",
|
||||||
|
"title_cow_selection": "Cow Selection",
|
||||||
|
"title_rate_cow": "Rate Cow",
|
||||||
|
"header_photos": "Photos",
|
||||||
|
"header_cow_details": "Cow Details",
|
||||||
|
"header_feature_ratings": "Feature Ratings",
|
||||||
|
"header_settings": "Settings",
|
||||||
|
"subtitle_home": "Record and manage cow information easily.",
|
||||||
|
"btn_view_gallery": "View Saved Cow Profiles",
|
||||||
|
"btn_select_cow": "Add New Cow Profile",
|
||||||
|
"label_algorithm": "Algorithm",
|
||||||
|
"label_match_threshold": "Match Threshold",
|
||||||
|
"label_auto_capture": "Auto Capture",
|
||||||
|
"label_enable_debug": "Enable Debug",
|
||||||
|
"label_mask_display": "Show Segmentation Mask",
|
||||||
|
"btn_edit": "Edit",
|
||||||
|
"btn_rate": "Rate",
|
||||||
|
"btn_delete": "Delete",
|
||||||
|
"btn_save_rating": "Save Rating",
|
||||||
|
"btn_retake": "Retake Photo",
|
||||||
|
"btn_exit": "Exit",
|
||||||
|
"hint_search_profiles": "Search profiles...",
|
||||||
|
"hint_comments": "Comments",
|
||||||
|
"toast_image_deleted": "Image deleted",
|
||||||
|
"toast_error_deleting_image": "Error deleting image",
|
||||||
|
"toast_ratings_saved": "Ratings Saved!",
|
||||||
|
"toast_error_saving_ratings": "Error saving ratings",
|
||||||
|
"toast_profile_deleted": "Cow profile deleted",
|
||||||
|
"text_cow_id": "Cow ID:",
|
||||||
|
"text_no_details": "No details available",
|
||||||
|
"label_species": "Species:",
|
||||||
|
"label_breed": "Breed:",
|
||||||
|
"label_age": "Age:",
|
||||||
|
"unit_years": "years",
|
||||||
|
"label_milk_yield": "Milk Yield:",
|
||||||
|
"unit_liters": "L",
|
||||||
|
"label_calving_no": "Calving #:",
|
||||||
|
"label_status": "Status:",
|
||||||
|
"hint_species": "Species",
|
||||||
|
"hint_breed": "Breed",
|
||||||
|
"hint_age": "Age (Years)",
|
||||||
|
"hint_milk_yield": "Milk Yield (L)",
|
||||||
|
"hint_calving_number": "Calving Number",
|
||||||
|
"label_reproductive_status": "Reproductive Status",
|
||||||
|
"radio_pregnant": "Pregnant",
|
||||||
|
"radio_calved": "Calved",
|
||||||
|
"radio_none": "None",
|
||||||
|
"hint_description": "Description",
|
||||||
|
"label_upload_photos": "Upload Photos",
|
||||||
|
"text_front_view": "Front View",
|
||||||
|
"text_rear_view": "Rear View",
|
||||||
|
"text_left_side": "Left Side",
|
||||||
|
"text_right_side": "Right Side",
|
||||||
|
"text_angle_view": "Angle View",
|
||||||
|
"text_left_angle": "Left Angle",
|
||||||
|
"text_right_angle": "Right Angle",
|
||||||
|
"btn_save_profile": "Save Profile",
|
||||||
|
"btn_cancel": "Cancel",
|
||||||
|
"toast_profile_saved": "Profile Saved!",
|
||||||
|
"toast_error_saving_profile": "Error saving profile:",
|
||||||
|
"toast_capture_failed": "Photo capture failed",
|
||||||
|
"toast_saved_as": "Saved as",
|
||||||
|
"toast_error_saving_image": "Error saving image",
|
||||||
|
"content_desc_back": "Back",
|
||||||
|
"content_desc_full_screen_image": "Full Screen Image",
|
||||||
|
"species_cow": "Cow",
|
||||||
|
"species_buffalo": "Buffalo",
|
||||||
|
"breed_holstein": "Holstein Friesian",
|
||||||
|
"breed_jersey": "Jersey",
|
||||||
|
"breed_sahiwal": "Sahiwal",
|
||||||
|
"breed_gir": "Gir",
|
||||||
|
"breed_red_sindhi": "Red Sindhi",
|
||||||
|
"breed_murrah": "Murrah",
|
||||||
|
"breed_surti": "Surti",
|
||||||
|
"feature_stature": "Stature",
|
||||||
|
"feature_chest_width": "Chest width",
|
||||||
|
"feature_body_depth": "Body depth",
|
||||||
|
"feature_angularity": "Angularity",
|
||||||
|
"feature_rump_angle": "Rump angle",
|
||||||
|
"feature_rump_width": "Rump width",
|
||||||
|
"feature_rear_legs_set": "Rear legs set",
|
||||||
|
"feature_rear_legs_rear_view": "Rear legs rear view",
|
||||||
|
"feature_foot_angle": "Foot angle",
|
||||||
|
"feature_fore_udder_attachment": "Fore udder attachment",
|
||||||
|
"feature_rear_udder_height": "Rear udder height",
|
||||||
|
"feature_central_ligament": "Central ligament",
|
||||||
|
"feature_udder_depth": "Udder depth",
|
||||||
|
"feature_front_teat_position": "Front teat position",
|
||||||
|
"feature_teat_length": "Teat length",
|
||||||
|
"feature_rear_teat_position": "Rear teat position",
|
||||||
|
"feature_locomotion": "Locomotion",
|
||||||
|
"feature_body_condition_score": "Body condition score",
|
||||||
|
"feature_hock_development": "Hock development",
|
||||||
|
"feature_bone_structure": "Bone structure",
|
||||||
|
"feature_rear_udder_width": "Rear udder width",
|
||||||
|
"feature_teat_thickness": "Teat thickness",
|
||||||
|
"feature_muscularity": "Muscularity",
|
||||||
|
"algo_hamming": "Hamming Distance",
|
||||||
|
"algo_euclidean": "Euclidean Distance",
|
||||||
|
"algo_jaccard": "Jaccard Similarity"
|
||||||
|
},
|
||||||
|
"Hindi": {
|
||||||
|
"app_name": "पशु रेटिंग",
|
||||||
|
"title_home": "पशु रेटिंग",
|
||||||
|
"title_gallery": "सहेजे गए गाय प्रोफाइल",
|
||||||
|
"title_add_cow_details": "गाय का विवरण जोड़ें",
|
||||||
|
"title_cow_selection": "गाय का चयन",
|
||||||
|
"title_rate_cow": "गाय का मूल्यांकन",
|
||||||
|
"header_photos": "तस्वीरें",
|
||||||
|
"header_cow_details": "गाय का विवरण",
|
||||||
|
"header_feature_ratings": "विशेषता रेटिंग",
|
||||||
|
"header_settings": "सेटिंग्स",
|
||||||
|
"subtitle_home": "गाय की जानकारी आसानी से रिकॉर्ड और प्रबंधित करें।",
|
||||||
|
"btn_view_gallery": "सहेजे गए प्रोफाइल देखें",
|
||||||
|
"btn_select_cow": "नई गाय प्रोफ़ाइल जोड़ें",
|
||||||
|
"label_algorithm": "एल्गोरिदम",
|
||||||
|
"label_match_threshold": "मैच थ्रेसहोल्ड",
|
||||||
|
"label_auto_capture": "ऑटो कैप्चर",
|
||||||
|
"label_enable_debug": "डिबग सक्षम करें",
|
||||||
|
"label_mask_display": "सेगमेंटेशन मास्क दिखाएं",
|
||||||
|
"btn_edit": "संपादित करें",
|
||||||
|
"btn_rate": "रेट करें",
|
||||||
|
"btn_delete": "हटाएँ",
|
||||||
|
"btn_save_rating": "रेटिंग सहेजें",
|
||||||
|
"btn_retake": "फोटो फिर से लें",
|
||||||
|
"btn_exit": "बाहर जाएं",
|
||||||
|
"hint_search_profiles": "प्रोफ़ाइल खोजें...",
|
||||||
|
"hint_comments": "टिप्पणियाँ",
|
||||||
|
"toast_image_deleted": "छवि हटा दी गई",
|
||||||
|
"toast_error_deleting_image": "छवि हटाने में त्रुटि",
|
||||||
|
"toast_ratings_saved": "रेटिंग सहेजी गई!",
|
||||||
|
"toast_error_saving_ratings": "रेटिंग सहेजने में त्रुटि",
|
||||||
|
"toast_profile_deleted": "गाय प्रोफ़ाइल हटाई गई",
|
||||||
|
"text_cow_id": "गाय आईडी:",
|
||||||
|
"text_no_details": "कोई विवरण उपलब्ध नहीं",
|
||||||
|
"label_species": "प्रजाति:",
|
||||||
|
"label_breed": "नस्ल:",
|
||||||
|
"label_age": "आयु:",
|
||||||
|
"unit_years": "वर्ष",
|
||||||
|
"label_milk_yield": "दूध की उपज:",
|
||||||
|
"unit_liters": "L",
|
||||||
|
"label_calving_no": "बछड़ों की संख्या:",
|
||||||
|
"label_status": "स्थिति:",
|
||||||
|
"hint_species": "प्रजाति",
|
||||||
|
"hint_breed": "नस्ल",
|
||||||
|
"hint_age": "आयु (वर्ष)",
|
||||||
|
"hint_milk_yield": "दूध की उपज (L)",
|
||||||
|
"hint_calving_number": "बछड़ों की संख्या",
|
||||||
|
"label_reproductive_status": "प्रजनन स्थिति",
|
||||||
|
"radio_pregnant": "गर्भवती",
|
||||||
|
"radio_calved": "बछड़ा हुआ",
|
||||||
|
"radio_none": "कोई नहीं",
|
||||||
|
"hint_description": "विवरण",
|
||||||
|
"label_upload_photos": "तस्वीरें अपलोड करें",
|
||||||
|
"text_front_view": "सामने का दृश्य",
|
||||||
|
"text_rear_view": "पीछे का दृश्य",
|
||||||
|
"text_left_side": "बाईं ओर",
|
||||||
|
"text_right_side": "दाईं ओर",
|
||||||
|
"text_angle_view": "कोणीय दृश्य",
|
||||||
|
"text_left_angle": "बायां कोण",
|
||||||
|
"text_right_angle": "दायां कोण",
|
||||||
|
"btn_save_profile": "प्रोफ़ाइल सहेजें",
|
||||||
|
"btn_cancel": "रद्द करें",
|
||||||
|
"toast_profile_saved": "प्रोफ़ाइल सहेजा गया!",
|
||||||
|
"toast_error_saving_profile": "प्रोफ़ाइल सहेजने में त्रुटि:",
|
||||||
|
"toast_capture_failed": "फोटो कैप्चर विफल",
|
||||||
|
"toast_saved_as": "के रूप में सहेजा गया",
|
||||||
|
"toast_error_saving_image": "छवि सहेजने में त्रुटि",
|
||||||
|
"content_desc_back": "वापस",
|
||||||
|
"content_desc_full_screen_image": "पूर्ण स्क्रीन छवि",
|
||||||
|
"species_cow": "गाय",
|
||||||
|
"species_buffalo": "भैंस",
|
||||||
|
"breed_holstein": "होल्सटीन फ्राइज़ियन",
|
||||||
|
"breed_jersey": "जर्सी",
|
||||||
|
"breed_sahiwal": "साहिवाल",
|
||||||
|
"breed_gir": "गिर",
|
||||||
|
"breed_red_sindhi": "लाल सिंधी",
|
||||||
|
"breed_murrah": "मुर्रा",
|
||||||
|
"breed_surti": "सुरती",
|
||||||
|
"feature_stature": "कद",
|
||||||
|
"feature_chest_width": "छाती की चौड़ाई",
|
||||||
|
"feature_body_depth": "शरीर की गहराई",
|
||||||
|
"feature_angularity": "कोणीयता",
|
||||||
|
"feature_rump_angle": "रंप कोण",
|
||||||
|
"feature_rump_width": "रंप चौड़ाई",
|
||||||
|
"feature_rear_legs_set": "पिछले पैर सेट",
|
||||||
|
"feature_rear_legs_rear_view": "पिछले पैर पीछे का दृश्य",
|
||||||
|
"feature_foot_angle": "पैर का कोण",
|
||||||
|
"feature_fore_udder_attachment": "आगे का अडर जुड़ाव",
|
||||||
|
"feature_rear_udder_height": "पीछे के अडर की ऊंचाई",
|
||||||
|
"feature_central_ligament": "केंद्रीय लिगामेंट",
|
||||||
|
"feature_udder_depth": "अडर की गहराई",
|
||||||
|
"feature_front_teat_position": "सामने के थन की स्थिति",
|
||||||
|
"feature_teat_length": "थन की लंबाई",
|
||||||
|
"feature_rear_teat_position": "पीछे के थन की स्थिति",
|
||||||
|
"feature_locomotion": "चाल",
|
||||||
|
"feature_body_condition_score": "शारीरिक स्थिति स्कोर",
|
||||||
|
"feature_hock_development": "हॉक विकास",
|
||||||
|
"feature_bone_structure": "हड्डी की संरचना",
|
||||||
|
"feature_rear_udder_width": "पीछे के अडर की चौड़ाई",
|
||||||
|
"feature_teat_thickness": "थन की मोटाई",
|
||||||
|
"feature_muscularity": "मांसलता",
|
||||||
|
"algo_hamming": "हैमिंग दूरी",
|
||||||
|
"algo_euclidean": "यूक्लिडियन दूरी",
|
||||||
|
"algo_jaccard": "जैकार्ड समानता"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,127 +0,0 @@
|
||||||
<resources>
|
|
||||||
<string name="app_name">पशु रेटिंग</string>
|
|
||||||
<string name="title_home">पशु रेटिंग</string>
|
|
||||||
<string name="title_gallery">सहेजे गए गाय प्रोफाइल</string>
|
|
||||||
<string name="title_add_cow_details">गाय का विवरण जोड़ें</string>
|
|
||||||
<string name="title_cow_selection">गाय का चयन</string>
|
|
||||||
<string name="title_rate_cow">गाय का मूल्यांकन</string>
|
|
||||||
|
|
||||||
<string name="header_photos">तस्वीरें</string>
|
|
||||||
<string name="header_cow_details">गाय का विवरण</string>
|
|
||||||
<string name="header_feature_ratings">विशेषता रेटिंग</string>
|
|
||||||
<string name="header_settings">सेटिंग्स</string>
|
|
||||||
|
|
||||||
<string name="subtitle_home">गाय की जानकारी आसानी से रिकॉर्ड और प्रबंधित करें।</string>
|
|
||||||
|
|
||||||
<string name="btn_view_gallery">सहेजे गए प्रोफाइल देखें</string>
|
|
||||||
<string name="btn_select_cow">नई गाय प्रोफ़ाइल जोड़ें</string>
|
|
||||||
|
|
||||||
<string name="label_algorithm">एल्गोरिदम</string>
|
|
||||||
<string name="label_match_threshold">मैच थ्रेसहोल्ड</string>
|
|
||||||
<string name="label_auto_capture">ऑटो कैप्चर</string>
|
|
||||||
<string name="label_enable_debug">डिबग सक्षम करें</string>
|
|
||||||
<string name="label_mask_display">सेगमेंटेशन मास्क दिखाएं</string>
|
|
||||||
|
|
||||||
<string name="btn_edit">संपादित करें</string>
|
|
||||||
<string name="btn_rate">रेट करें</string>
|
|
||||||
<string name="btn_delete">हटाएँ</string>
|
|
||||||
<string name="btn_save_rating">रेटिंग सहेजें</string>
|
|
||||||
<string name="btn_retake">फोटो फिर से लें</string>
|
|
||||||
<string name="btn_exit">बाहर जाएं</string>
|
|
||||||
|
|
||||||
<string name="hint_search_profiles">प्रोफ़ाइल खोजें…</string>
|
|
||||||
<string name="hint_comments">टिप्पणियाँ</string>
|
|
||||||
|
|
||||||
<string name="toast_image_deleted">छवि हटा दी गई</string>
|
|
||||||
<string name="toast_error_deleting_image">छवि हटाने में त्रुटि</string>
|
|
||||||
<string name="toast_ratings_saved">रेटिंग सहेजी गई!</string>
|
|
||||||
<string name="toast_error_saving_ratings">रेटिंग सहेजने में त्रुटि</string>
|
|
||||||
<string name="toast_profile_deleted">गाय प्रोफ़ाइल हटाई गई</string>
|
|
||||||
|
|
||||||
<string name="text_cow_id">गाय आईडी:</string>
|
|
||||||
<string name="text_no_details">कोई विवरण उपलब्ध नहीं</string>
|
|
||||||
|
|
||||||
<string name="label_species">प्रजाति:</string>
|
|
||||||
<string name="label_breed">नस्ल:</string>
|
|
||||||
<string name="label_age">आयु:</string>
|
|
||||||
<string name="unit_years">वर्ष</string>
|
|
||||||
|
|
||||||
<string name="label_milk_yield">दूध की उपज:</string>
|
|
||||||
<string name="unit_liters">L</string>
|
|
||||||
|
|
||||||
<string name="label_calving_no">बछड़ों की संख्या:</string>
|
|
||||||
<string name="label_status">स्थिति:</string>
|
|
||||||
|
|
||||||
<string name="hint_species">प्रजाति</string>
|
|
||||||
<string name="hint_breed">नस्ल</string>
|
|
||||||
<string name="hint_age">आयु (वर्ष)</string>
|
|
||||||
<string name="hint_milk_yield">दूध की उपज (L)</string>
|
|
||||||
<string name="hint_calving_number">बछड़ों की संख्या</string>
|
|
||||||
|
|
||||||
<string name="label_reproductive_status">प्रजनन स्थिति</string>
|
|
||||||
<string name="radio_pregnant">गर्भवती</string>
|
|
||||||
<string name="radio_calved">बछड़ा हुआ</string>
|
|
||||||
<string name="radio_none">कोई नहीं</string>
|
|
||||||
|
|
||||||
<string name="hint_description">विवरण</string>
|
|
||||||
<string name="label_upload_photos">तस्वीरें अपलोड करें</string>
|
|
||||||
|
|
||||||
<string name="text_front_view">सामने का दृश्य</string>
|
|
||||||
<string name="text_rear_view">पीछे का दृश्य</string>
|
|
||||||
<string name="text_left_side">बाईं ओर</string>
|
|
||||||
<string name="text_right_side">दाईं ओर</string>
|
|
||||||
<string name="text_angle_view">कोणीय दृश्य</string>
|
|
||||||
<string name="text_left_angle">बायां कोण</string>
|
|
||||||
<string name="text_right_angle">दायां कोण</string>
|
|
||||||
|
|
||||||
<string name="btn_save_profile">प्रोफ़ाइल सहेजें</string>
|
|
||||||
<string name="btn_cancel">रद्द करें</string>
|
|
||||||
|
|
||||||
<string name="toast_profile_saved">प्रोफ़ाइल सहेजा गया!</string>
|
|
||||||
<string name="toast_error_saving_profile">प्रोफ़ाइल सहेजने में त्रुटि:</string>
|
|
||||||
<string name="toast_capture_failed">फोटो कैप्चर विफल</string>
|
|
||||||
<string name="toast_saved_as">के रूप में सहेजा गया</string>
|
|
||||||
<string name="toast_error_saving_image">छवि सहेजने में त्रुटि</string>
|
|
||||||
|
|
||||||
<string name="content_desc_back">वापस</string>
|
|
||||||
<string name="content_desc_full_screen_image">पूर्ण स्क्रीन छवि</string>
|
|
||||||
|
|
||||||
<string name="species_cow">गाय</string>
|
|
||||||
<string name="species_buffalo">भैंस</string>
|
|
||||||
|
|
||||||
<string name="breed_holstein">होल्सटीन फ्राइज़ियन</string>
|
|
||||||
<string name="breed_jersey">जर्सी</string>
|
|
||||||
<string name="breed_sahiwal">साहिवाल</string>
|
|
||||||
<string name="breed_gir">गिर</string>
|
|
||||||
<string name="breed_red_sindhi">लाल सिंधी</string>
|
|
||||||
<string name="breed_murrah">मुर्रा</string>
|
|
||||||
<string name="breed_surti">सुरती</string>
|
|
||||||
|
|
||||||
<string name="feature_stature">कद</string>
|
|
||||||
<string name="feature_chest_width">छाती की चौड़ाई</string>
|
|
||||||
<string name="feature_body_depth">शरीर की गहराई</string>
|
|
||||||
<string name="feature_angularity">कोणीयता</string>
|
|
||||||
<string name="feature_rump_angle">रंप कोण</string>
|
|
||||||
<string name="feature_rump_width">रंप चौड़ाई</string>
|
|
||||||
<string name="feature_rear_legs_set">पिछले पैर सेट</string>
|
|
||||||
<string name="feature_rear_legs_rear_view">पिछले पैर पीछे का दृश्य</string>
|
|
||||||
<string name="feature_foot_angle">पैर का कोण</string>
|
|
||||||
<string name="feature_fore_udder_attachment">आगे का अडर जुड़ाव</string>
|
|
||||||
<string name="feature_rear_udder_height">पीछे के अडर की ऊंचाई</string>
|
|
||||||
<string name="feature_central_ligament">केंद्रीय लिगामेंट</string>
|
|
||||||
<string name="feature_udder_depth">अडर की गहराई</string>
|
|
||||||
<string name="feature_front_teat_position">सामने के थन की स्थिति</string>
|
|
||||||
<string name="feature_teat_length">थन की लंबाई</string>
|
|
||||||
<string name="feature_rear_teat_position">पीछे के थन की स्थिति</string>
|
|
||||||
<string name="feature_locomotion">चाल</string>
|
|
||||||
<string name="feature_body_condition_score">शारीरिक स्थिति स्कोर</string>
|
|
||||||
<string name="feature_hock_development">हॉक विकास</string>
|
|
||||||
<string name="feature_bone_structure">हड्डी की संरचना</string>
|
|
||||||
<string name="feature_rear_udder_width">पीछे के अडर की चौड़ाई</string>
|
|
||||||
<string name="feature_teat_thickness">थन की मोटाई</string>
|
|
||||||
<string name="feature_muscularity">मांसलता</string>
|
|
||||||
|
|
||||||
<string name="algo_hamming">हैमिंग दूरी</string>
|
|
||||||
<string name="algo_euclidean">यूक्लिडियन दूरी</string>
|
|
||||||
<string name="algo_jaccard">जैकार्ड समानता</string>
|
|
||||||
</resources>
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="purple_200">#FFBB86FC</color>
|
||||||
|
<color name="purple_500">#FF6200EE</color>
|
||||||
|
<color name="purple_700">#FF3700B3</color>
|
||||||
|
<color name="teal_200">#FF03DAC5</color>
|
||||||
|
<color name="teal_700">#FF018786</color>
|
||||||
|
<color name="black">#FF000000</color>
|
||||||
|
<color name="white">#FFFFFFFF</color>
|
||||||
|
|
||||||
|
<!-- Semantic Colors for AnimalRating (Dark Mode) -->
|
||||||
|
<color name="text_primary">#EFEBE9</color>
|
||||||
|
<color name="text_secondary">#BCAAA4</color>
|
||||||
|
<color name="text_tertiary">#A1887F</color>
|
||||||
|
<color name="page_background">#121212</color>
|
||||||
|
<color name="surface_background">#1E1E1E</color>
|
||||||
|
<color name="input_background">#2C2C2C</color>
|
||||||
|
<color name="icon_tint_primary">#BCAAA4</color>
|
||||||
|
</resources>
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<style name="Theme.AnimalRating" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
<item name="colorPrimary">#A1887F</item>
|
||||||
|
<item name="colorPrimaryVariant">#6D4C41</item>
|
||||||
|
<item name="colorOnPrimary">#000000</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">#FF8A65</item>
|
||||||
|
<item name="colorSecondaryVariant">#FF8A65</item>
|
||||||
|
<item name="colorOnSecondary">#000000</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
|
|
@ -5,24 +5,16 @@
|
||||||
<color name="purple_700">#FF3700B3</color>
|
<color name="purple_700">#FF3700B3</color>
|
||||||
<color name="teal_200">#FF03DAC5</color>
|
<color name="teal_200">#FF03DAC5</color>
|
||||||
<color name="teal_700">#FF018786</color>
|
<color name="teal_700">#FF018786</color>
|
||||||
<color name="earthy">#6D4C41</color>
|
|
||||||
<color name="black">#FF000000</color>
|
<color name="black">#FF000000</color>
|
||||||
<color name="white">#FFFFFFFF</color>
|
<color name="white">#FFFFFFFF</color>
|
||||||
|
|
||||||
|
<!-- Semantic Colors for AnimalRating -->
|
||||||
|
<color name="text_primary">#3E2723</color>
|
||||||
|
<color name="text_secondary">#5D4037</color>
|
||||||
|
<color name="text_tertiary">#6D4C41</color>
|
||||||
|
<color name="page_background">#F7F7F7</color>
|
||||||
<color name="surface_background">#FFFFFF</color>
|
<color name="surface_background">#FFFFFF</color>
|
||||||
<color name="page_background">#FFFFFF</color>
|
|
||||||
<color name="text_primary">#212121</color>
|
|
||||||
<color name="text_secondary">#757575</color>
|
|
||||||
<color name="text_tertiary">#BDBDBD</color>
|
|
||||||
<color name="input_background">#F5F5F5</color>
|
<color name="input_background">#F5F5F5</color>
|
||||||
<color name="icon_tint_primary">#212121</color>
|
<color name="icon_tint_primary">#5D4037</color>
|
||||||
|
<color name="placeholder_background">#E0E0E0</color>
|
||||||
<color name="camera_overlay_button">#80000000</color>
|
|
||||||
<color name="shutter_red">#D32F2F</color>
|
|
||||||
|
|
||||||
<color name="text_brown">#5D4037</color>
|
|
||||||
<color name="text_header_brown">#3E2723</color>
|
|
||||||
<color name="brown_light_background">#EFEBE9</color>
|
|
||||||
<color name="switch_track_brown">#8D6E63</color>
|
|
||||||
<color name="translucent_white">#80FFFFFF</color>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,127 +1,3 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">LivingAI</string>
|
<string name="app_name">AnimalRating</string>
|
||||||
<string name="title_home">LivingAI</string>
|
|
||||||
<string name="title_gallery">Saved Cow Profiles</string>
|
|
||||||
<string name="title_add_cow_details">Add Cow Details</string>
|
|
||||||
<string name="title_cow_selection">Cow Selection</string>
|
|
||||||
<string name="title_rate_cow">Rate Cow</string>
|
|
||||||
|
|
||||||
<string name="header_photos">Photos</string>
|
|
||||||
<string name="header_cow_details">Cow Details</string>
|
|
||||||
<string name="header_feature_ratings">Feature Ratings</string>
|
|
||||||
<string name="header_settings">Debug Configs</string>
|
|
||||||
|
|
||||||
<string name="subtitle_home">Record and manage cow information easily.</string>
|
|
||||||
|
|
||||||
<string name="btn_view_gallery">View Saved Cow Profiles</string>
|
|
||||||
<string name="btn_select_cow">Add New Cow Profile</string>
|
|
||||||
|
|
||||||
<string name="label_algorithm">Algorithm</string>
|
|
||||||
<string name="label_match_threshold">Match Threshold</string>
|
|
||||||
<string name="label_auto_capture">Auto Capture</string>
|
|
||||||
<string name="label_enable_debug">Enable Debug</string>
|
|
||||||
<string name="label_mask_display">Show Segmentation Mask</string>
|
|
||||||
|
|
||||||
<string name="btn_edit">Edit</string>
|
|
||||||
<string name="btn_rate">Rate</string>
|
|
||||||
<string name="btn_delete">Delete</string>
|
|
||||||
<string name="btn_save_rating">Save Rating</string>
|
|
||||||
<string name="btn_retake">Retake Photo</string>
|
|
||||||
<string name="btn_exit">Exit</string>
|
|
||||||
|
|
||||||
<string name="hint_search_profiles">Search profiles...</string>
|
|
||||||
<string name="hint_comments">Comments</string>
|
|
||||||
|
|
||||||
<string name="toast_image_deleted">Image deleted</string>
|
|
||||||
<string name="toast_error_deleting_image">Error deleting image</string>
|
|
||||||
<string name="toast_ratings_saved">Ratings Saved!</string>
|
|
||||||
<string name="toast_error_saving_ratings">Error saving ratings</string>
|
|
||||||
<string name="toast_profile_deleted">Cow profile deleted</string>
|
|
||||||
|
|
||||||
<string name="text_cow_id">Cow ID:</string>
|
|
||||||
<string name="text_no_details">No details available</string>
|
|
||||||
|
|
||||||
<string name="label_species">Species:</string>
|
|
||||||
<string name="label_breed">Breed:</string>
|
|
||||||
<string name="label_age">Age:</string>
|
|
||||||
<string name="unit_years">years</string>
|
|
||||||
|
|
||||||
<string name="label_milk_yield">Milk Yield:</string>
|
|
||||||
<string name="unit_liters">L</string>
|
|
||||||
|
|
||||||
<string name="label_calving_no">Calving #:</string>
|
|
||||||
<string name="label_status">Status:</string>
|
|
||||||
|
|
||||||
<string name="hint_species">Species</string>
|
|
||||||
<string name="hint_breed">Breed</string>
|
|
||||||
<string name="hint_age">Age (Years)</string>
|
|
||||||
<string name="hint_milk_yield">Milk Yield (L)</string>
|
|
||||||
<string name="hint_calving_number">Calving Number</string>
|
|
||||||
|
|
||||||
<string name="label_reproductive_status">Reproductive Status</string>
|
|
||||||
<string name="radio_pregnant">Pregnant</string>
|
|
||||||
<string name="radio_calved">Calved</string>
|
|
||||||
<string name="radio_none">None</string>
|
|
||||||
|
|
||||||
<string name="hint_description">Description</string>
|
|
||||||
<string name="label_upload_photos">Upload Photos</string>
|
|
||||||
|
|
||||||
<string name="text_front_view">Front View</string>
|
|
||||||
<string name="text_rear_view">Rear View</string>
|
|
||||||
<string name="text_left_side">Left Side</string>
|
|
||||||
<string name="text_right_side">Right Side</string>
|
|
||||||
<string name="text_angle_view">Angle View</string>
|
|
||||||
<string name="text_left_angle">Left Angle</string>
|
|
||||||
<string name="text_right_angle">Right Angle</string>
|
|
||||||
|
|
||||||
<string name="btn_save_profile">Save Profile</string>
|
|
||||||
<string name="btn_cancel">Cancel</string>
|
|
||||||
|
|
||||||
<string name="toast_profile_saved">Profile Saved!</string>
|
|
||||||
<string name="toast_error_saving_profile">Error saving profile:</string>
|
|
||||||
<string name="toast_capture_failed">Photo capture failed</string>
|
|
||||||
<string name="toast_saved_as">Saved as</string>
|
|
||||||
<string name="toast_error_saving_image">Error saving image</string>
|
|
||||||
|
|
||||||
<string name="content_desc_back">Back</string>
|
|
||||||
<string name="content_desc_full_screen_image">Full Screen Image</string>
|
|
||||||
|
|
||||||
<string name="species_cow">Cow</string>
|
|
||||||
<string name="species_buffalo">Buffalo</string>
|
|
||||||
|
|
||||||
<string name="breed_holstein">Holstein Friesian</string>
|
|
||||||
<string name="breed_jersey">Jersey</string>
|
|
||||||
<string name="breed_sahiwal">Sahiwal</string>
|
|
||||||
<string name="breed_gir">Gir</string>
|
|
||||||
<string name="breed_red_sindhi">Red Sindhi</string>
|
|
||||||
<string name="breed_murrah">Murrah</string>
|
|
||||||
<string name="breed_surti">Surti</string>
|
|
||||||
|
|
||||||
<string name="feature_stature">Stature</string>
|
|
||||||
<string name="feature_chest_width">Chest width</string>
|
|
||||||
<string name="feature_body_depth">Body depth</string>
|
|
||||||
<string name="feature_angularity">Angularity</string>
|
|
||||||
<string name="feature_rump_angle">Rump angle</string>
|
|
||||||
<string name="feature_rump_width">Rump width</string>
|
|
||||||
<string name="feature_rear_legs_set">Rear legs set</string>
|
|
||||||
<string name="feature_rear_legs_rear_view">Rear legs rear view</string>
|
|
||||||
<string name="feature_foot_angle">Foot angle</string>
|
|
||||||
<string name="feature_fore_udder_attachment">Fore udder attachment</string>
|
|
||||||
<string name="feature_rear_udder_height">Rear udder height</string>
|
|
||||||
<string name="feature_central_ligament">Central ligament</string>
|
|
||||||
<string name="feature_udder_depth">Udder depth</string>
|
|
||||||
<string name="feature_front_teat_position">Front teat position</string>
|
|
||||||
<string name="feature_teat_length">Teat length</string>
|
|
||||||
<string name="feature_rear_teat_position">Rear teat position</string>
|
|
||||||
<string name="feature_locomotion">Locomotion</string>
|
|
||||||
<string name="feature_body_condition_score">Body condition score</string>
|
|
||||||
<string name="feature_hock_development">Hock development</string>
|
|
||||||
<string name="feature_bone_structure">Bone structure</string>
|
|
||||||
<string name="feature_rear_udder_width">Rear udder width</string>
|
|
||||||
<string name="feature_teat_thickness">Teat thickness</string>
|
|
||||||
<string name="feature_muscularity">Muscularity</string>
|
|
||||||
|
|
||||||
<string name="algo_hamming">Hamming Distance</string>
|
|
||||||
<string name="algo_euclidean">Euclidean Distance</string>
|
|
||||||
<string name="algo_jaccard">Jaccard Similarity</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="Theme.LivingAI" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
|
||||||
<item name="colorPrimary">@color/purple_500</item>
|
<style name="Theme.AnimalRating" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
<!-- Primary brand color. -->
|
||||||
<item name="colorOnPrimary">@color/white</item>
|
<item name="colorPrimary">#6D4C41</item>
|
||||||
<item name="colorSecondary">@color/teal_200</item>
|
<item name="colorPrimaryVariant">#5D4037</item>
|
||||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
<item name="colorOnPrimary">#FFFFFF</item>
|
||||||
<item name="colorOnSecondary">@color/black</item>
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">#FF5722</item>
|
||||||
|
<item name="colorSecondaryVariant">#E64A19</item>
|
||||||
|
<item name="colorOnSecondary">#FFFFFF</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.livingai
|
package com.example.animalrating
|
||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
|
|
@ -8,8 +8,6 @@ espressoCore = "3.7.0"
|
||||||
lifecycleRuntimeKtx = "2.10.0"
|
lifecycleRuntimeKtx = "2.10.0"
|
||||||
activityCompose = "1.12.0"
|
activityCompose = "1.12.0"
|
||||||
composeBom = "2024.09.00"
|
composeBom = "2024.09.00"
|
||||||
appcompat = "1.7.0"
|
|
||||||
material = "1.12.0"
|
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
|
|
@ -26,10 +24,9 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u
|
||||||
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||||
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||||
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
|
||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#Sat Nov 29 09:53:57 IST 2025
|
#Sun Nov 23 20:12:35 IST 2025
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,6 @@ dependencyResolutionManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "LivingAI"
|
rootProject.name = "AnimalRating"
|
||||||
include(":app")
|
include(":app")
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Adobe Stock - https://stock.adobe.com/
|
||||||
Loading…
Reference in New Issue