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
@@ -0,0 +1,43 @@
package com.example.smishingdetectionapp;

import android.content.Context;
import com.example.smishingdetectionapp.detections.DatabaseAccess;

public class DatabaseThreatRepository implements ThreatRepository {

private static final int SAFE = 0; // LOW
private static final int CAUTION = 1; // MEDIUM
private static final int ALERT = 2; // HIGH

// Your requested bands (by COUNT, not percent):
// 0..14 -> LOW, 15..59 -> MEDIUM, >=60 -> HIGH
private static final int CAUTION_MIN_COUNT = 15;
private static final int ALERT_MIN_COUNT = 60;

private final Context context;

public DatabaseThreatRepository(Context context) {
this.context = context;
}

/** Legacy name: now returns the raw detection COUNT from DB. */
@Override
public int calculateThreatScore() {
DatabaseAccess db = DatabaseAccess.getInstance(context);
db.open();
try {
return db.getCounter(); // total detections
} finally {
db.close();
}
}

/** 0 = LOW, 1 = MEDIUM, 2 = HIGH based only on COUNT. */
@Override
public int getThreatLevel() {
int count = calculateThreatScore();
if (count >= ALERT_MIN_COUNT) return ALERT; // 60+
if (count >= CAUTION_MIN_COUNT) return CAUTION; // 15..59
return SAFE; // 0..14
}
}
196 changes: 123 additions & 73 deletions app/src/main/java/com/example/smishingdetectionapp/MainActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.smishingdetectionapp;

import android.content.Context;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.LiveData;

public class MainViewModel extends ViewModel {

private MutableLiveData<Integer> threatLevelLiveData;
private ThreatRepository threatRepository;

public MainViewModel(Context context) {
threatLevelLiveData = new MutableLiveData<>();
threatRepository = new DatabaseThreatRepository(context);
refreshThreatLevel();
}

public LiveData<Integer> getThreatLevel() {
return threatLevelLiveData;
}

public void refreshThreatLevel() {
int currentLevel = threatRepository.getThreatLevel();
threatLevelLiveData.setValue(currentLevel);
}

public int getCurrentScore() {
return threatRepository.calculateThreatScore();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.smishingdetectionapp;

public class MockThreatRepository implements ThreatRepository {

@Override
public int calculateThreatScore() {
// Mock data - simulating real threat detection
int newDetections24h = 1; // 1 new SMS threat in last 24h
int highSeverity7d = 1; // 1 high severity event in last 7d

// Scoring formula: new24h × 25 + high7d × 10
return (newDetections24h * 25) + (highSeverity7d * 10);
}

@Override
public int getThreatLevel() {
int score = calculateThreatScore();

// Thresholds from mockup: ≥70 ALERT, ≥30 CAUTION, else SAFE
if (score >= 70) {
return 2; // ALERT
} else if (score >= 30) {
return 1; // CAUTION
} else {
return 0; // SAFE
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.smishingdetectionapp;

public interface ThreatRepository {
int calculateThreatScore();
int getThreatLevel(); // 0=SAFE, 1=CAUTION, 2=ALERT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.smishingdetectionapp;

import android.content.Context;
import android.content.SharedPreferences;

public class ThreatThemeManager {

private static final String PREFS_NAME = "threat_preferences";
private static final String KEY_THREAT_LEVEL = "current_threat_level";

public int getDrawableForLevel(Context context, int threatLevel) {
switch (threatLevel) {
case 0: // SAFE
return R.drawable.counter_buttons_safe;
case 1: // CAUTION
return R.drawable.counter_buttons_caution;
case 2: // ALERT
return R.drawable.counter_buttons_alert;
default:
return R.drawable.counter_buttons_safe;
}
}

public void persistThreatLevel(Context context, int threatLevel) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit()
.putInt(KEY_THREAT_LEVEL, threatLevel)
.apply();
}

public int getPersistedThreatLevel(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
return prefs.getInt(KEY_THREAT_LEVEL, 0); // Default to SAFE if not found
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/counter_buttons_alert.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<gradient
android:type="linear"
android:startColor="#F44336"
android:endColor="#B71C1C"
android:angle="90" />
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/counter_buttons_caution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<gradient
android:type="linear"
android:startColor="#FF9800"
android:endColor="#E65100"
android:angle="90" />
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/counter_buttons_safe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<gradient
android:type="linear"
android:startColor="#4CAF50"
android:endColor="#2E7D32"
android:angle="90" />
</shape>
16 changes: 3 additions & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,10 @@
android:layout_height="101dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="@drawable/counter_buttons_safe"
app:layout_constraintTop_toBottomOf="@id/information_box"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/new_detections"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/counter_buttons" />

<TextView
android:id="@+id/new_counter"
android:layout_width="match_parent"
Expand Down Expand Up @@ -186,15 +181,10 @@
android:layout_height="100dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:background="@drawable/counter_buttons_safe"
app:layout_constraintTop_toBottomOf="@id/information_box"
app:layout_constraintEnd_toEndOf="parent">

<TextView
android:id="@+id/total_detections"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/counter_buttons" />

<TextView
android:id="@+id/total_counter"
android:layout_width="match_parent"
Expand Down Expand Up @@ -336,4 +326,4 @@

</ScrollView>

</RelativeLayout>
</RelativeLayout>