Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.example.smishingdetectionapp.detections.DatabaseAccess;
import com.example.smishingdetectionapp.detections.DetectionsActivity;
import com.example.smishingdetectionapp.riskmeter.RiskScannerTCActivity;
import com.example.smishingdetectionapp.ui.AnalyzeMessageActivity;
import com.example.smishingdetectionapp.notifications.NotificationPermissionDialogFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

Expand Down Expand Up @@ -89,6 +90,15 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
});




// Analyze Message Button
binding.btnAnalyzeMessage.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, AnalyzeMessageActivity.class);
startActivity(intent);
});

// Database connection
DatabaseAccess databaseAccess = DatabaseAccess.getInstance(getApplicationContext());
databaseAccess.open();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.example.smishingdetectionapp.ui

import android.os.Bundle
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.cardview.widget.CardView
import com.example.smishingdetectionapp.R
import androidx.core.text.HtmlCompat
import androidx.core.widget.doOnTextChanged

class AnalyzeMessageActivity : AppCompatActivity() {

private val riskyWords = listOf(
"click", "login", "account", "urgent", "verify", "link", "update", "suspend", "payment"
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_analyze_message)

val backButton = findViewById<ImageView>(R.id.back_button)
backButton.setOnClickListener {
finish()
}

val inputMessage = findViewById<EditText>(R.id.input_message)
val btnAnalyze = findViewById<Button>(R.id.btn_analyze)
val resultCard = findViewById<LinearLayout>(R.id.result_card)
val textRiskLevel = findViewById<TextView>(R.id.text_risk_level)
val textHighlighted = findViewById<TextView>(R.id.text_highlighted_result)
val resultLabelCard = findViewById<CardView>(R.id.simple_result_card)
val resultLabelText = findViewById<TextView>(R.id.result_text)

resultCard.visibility = View.GONE
resultLabelCard.visibility = View.GONE

btnAnalyze.setOnClickListener {
val message = inputMessage.text.toString().trim().lowercase()

if (message.isEmpty()) {
Toast.makeText(this, "Please enter a message.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

val foundWords = riskyWords.filter { message.contains(it, ignoreCase = true) }

val (riskLevel, backgroundDrawable) = when {
foundWords.size >= 4 -> "High Risk ❌" to R.drawable.card_background_high
foundWords.size >= 2 -> "Caution ⚠️" to R.drawable.card_background_caution
foundWords.isNotEmpty() -> "Suspicious ⚠️" to R.drawable.card_background_caution
else -> "Safe ✅" to R.drawable.card_background_safe
}

// Highlight risky words
var highlighted = message
foundWords.forEach {
highlighted = highlighted.replace(
it,
"<b><font color='red'>$it</font></b>",
ignoreCase = true
)
}

// Result Card
textRiskLevel.text = "Risk Level: $riskLevel"
textHighlighted.text = HtmlCompat.fromHtml(highlighted, HtmlCompat.FROM_HTML_MODE_LEGACY)
resultCard.setBackgroundResource(backgroundDrawable)
showResultCard(resultCard)

// Label Card
resultLabelText.text = if (foundWords.isNotEmpty()) "⚠️ Smishing Detected" else "✅ Safe Message"
resultLabelCard.setCardBackgroundColor(
ContextCompat.getColor(
this,
if (foundWords.isNotEmpty()) android.R.color.holo_red_light else android.R.color.holo_green_light
)
)
resultLabelCard.visibility = View.VISIBLE
}

inputMessage.doOnTextChanged { text, _, _, _ ->
if (text.isNullOrEmpty()) {
resultCard.visibility = View.GONE
resultLabelCard.visibility = View.GONE
}
}
}

private fun showResultCard(card: View) {
card.visibility = View.VISIBLE
card.alpha = 0f
card.animate().alpha(1f).setDuration(400).start()
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/card_background_caution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFF9C4" /> <!-- Light yellow -->
<corners android:radius="16dp" />
</shape>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/card_background_high.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFCDD2" /> <!-- Light red -->
<corners android:radius="16dp" />
</shape>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/card_background_safe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#C8E6C9" /> <!-- Light green -->
<corners android:radius="16dp" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/edit_text_rounded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E3F2FD" /> <!-- Light blue background -->
<corners android:radius="16dp" />
<padding
android:left="12dp"
android:top="12dp"
android:right="12dp"
android:bottom="12dp" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/result_card_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F1F9FF" /> <!-- Slightly different tint -->
<corners android:radius="16dp" />
<padding
android:left="16dp"
android:top="16dp"
android:right="16dp"
android:bottom="16dp" />
</shape>
Binary file added app/src/main/res/drawable/smishing_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions app/src/main/res/layout/activity_analyze_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="@android:color/white">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">

<!-- 🔙 Back Button -->
<ImageView
android:id="@+id/back_button"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginBottom="12dp"
android:contentDescription="Back"
android:src="@drawable/back_button" />

<!-- Logo -->
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dp"
android:contentDescription="@string/logo_desc"
android:src="@drawable/smishing_logo" />

<!-- Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_smish_or_safe"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@color/navy_blue"
android:layout_marginBottom="20dp" />

<!-- Message Input -->
<EditText
android:id="@+id/input_message"
android:layout_width="match_parent"
android:layout_height="150dp"
android:hint="@string/hint_input_message"
android:background="@drawable/edit_text_rounded"
android:padding="12dp"
android:textSize="16sp"
android:textColor="@android:color/black"
android:gravity="top"
android:inputType="textMultiLine"
android:maxLines="6"
android:scrollbars="vertical" />

<!-- Analyze Button -->
<Button
android:id="@+id/btn_analyze"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_analyze"
android:textAllCaps="false"
android:layout_marginTop="20dp"
android:elevation="4dp"
android:backgroundTint="@color/navy_blue"
android:textColor="@android:color/white"
android:padding="12dp" />

<!-- Progress Loader -->
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:visibility="gone" />

<!-- Results Card -->
<LinearLayout
android:id="@+id/result_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/result_card_background"
android:padding="16dp"
android:elevation="4dp"
android:layout_marginTop="24dp"
android:visibility="gone">

<TextView
android:id="@+id/text_risk_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Risk Level:"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/text_highlighted_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No analysis yet."
android:textColor="@color/black"
android:layout_marginTop="8dp"
android:textSize="16sp" />
</LinearLayout>

<!-- ✅ Simple Result Label Card -->
<androidx.cardview.widget.CardView
android:id="@+id/simple_result_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:elevation="4dp"
android:visibility="gone"
app:cardCornerRadius="12dp">

<TextView
android:id="@+id/result_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Analysis Result"
android:textSize="16sp"
android:textColor="@android:color/white"
android:gravity="center" />
</androidx.cardview.widget.CardView>

<!-- Educational Tip -->
<TextView
android:id="@+id/text_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tip_message"
android:textSize="14sp"
android:textColor="@color/red"
android:layout_marginTop="16dp" />

</LinearLayout>
</ScrollView>
56 changes: 40 additions & 16 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
<ScrollView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/baby_blue"
app:itemIconTint="@color/black"
app:itemTextColor="@color/black"
app:itemIconSize="25dp"
app:itemHorizontalTranslationEnabled="false"
app:labelVisibilityMode="labeled"
app:itemPaddingBottom="10dp"
android:theme="@style/Theme.SmishingDetectionApp"
app:menu="@menu/activity_main_drawer" >
</com.google.android.material.bottomnavigation.BottomNavigationView>
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation"
android:fillViewport="true">



<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -258,6 +249,39 @@
app:layout_constraintEnd_toEndOf="parent"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/btn_analyze_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/buttons_rounded"
android:text="Analyze a Message"
android:textColor="@android:color/black"
android:textSize="16sp"
android:padding="12dp"
app:layout_constraintTop_toBottomOf="@id/fragment_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/baby_blue"
app:itemIconTint="@color/black"
app:itemTextColor="@color/black"
app:itemIconSize="25dp"
app:itemHorizontalTranslationEnabled="false"
app:labelVisibilityMode="labeled"
app:itemPaddingBottom="10dp"
android:theme="@style/Theme.SmishingDetectionApp"
app:menu="@menu/activity_main_drawer" >
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
<string name="reporting_activity_btnSelectImage">Select Image (optional)</string>
<string name="reporting_activity_btnSubmitReport">SUBMIT</string>


<string name="alert">triangle with exclamation mark</string>

<!-- Account / Sorting -->
Expand Down Expand Up @@ -385,6 +386,16 @@
<string name="word_count_format">Words: %1$d / %2$d</string>
<string name="feedback_success">Feedback submitted successfully!</string>

<string name="alert_text">This is a placeholder alert message.</string>
<string name="news_list_description">Scrollable list of news articles</string>
<string name="title_smish_or_safe">Smish or Safe?</string>
<string name="hint_input_message">Paste the suspicious message here</string>
<string name="btn_analyze">Analyze Message</string>
<string name="label_risk_level">Risk Level: -</string>
<string name="no_analysis">No analysis yet.</string>
<string name="tip_message">Tip: Avoid clicking links in suspicious messages.</string>
<string name="logo_desc">App Logo</string>

<!-- feedback page -->
<string name="enter_name">Your name</string>
<string name="word_count_default">Words: 0 / 150</string>
Expand Down