This commit is contained in:
2023-10-06 21:46:14 +05:30
parent 4470e5d2b1
commit 84bb4d6886
9 changed files with 163 additions and 14 deletions

View File

@@ -184,7 +184,8 @@
</activity>
<!-- // app blocking stuff -->
<activity android:name=".appblocking.FUAActivity" />
<activity android:name=".appblocking.BlockApp" />
<activity android:name=".appblocking.BlockApp"
android:launchMode="singleTop"/>
<meta-data
android:name="com.onesignal.NotificationServiceExtension"

View File

@@ -1,22 +1,93 @@
package com.app.simplitend.appblocking;
import static com.app.simplitend.appblocking.TopAppDetectionService.BLOCKED_APP_NAME;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.app.simplitend.R;
import com.app.simplitend.welcome.activities.WelcomeActivity;
import java.util.List;
public class BlockApp extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.overlay_layout);
String appName = getIntent().getStringExtra(BLOCKED_APP_NAME);
textView = findViewById(R.id.block_app_text);
if (appName != null){
textView.setText(appName + " is blocked by SimpliTend");
}
findViewById(R.id.open_simplitent).setOnClickListener(view -> {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
try {
if (!runningTasks.isEmpty()) {
// There is at least one task on the activity stack
ActivityManager.RunningTaskInfo taskInfo = runningTasks.get(0);
ComponentName topActivity = taskInfo.topActivity;
// You can also check the number of activities in the task
int numActivities = taskInfo.numActivities;
if (numActivities > 1){
// There are activities below this screen to be shown
finish();
}else{
// no activities beneath this screen
throw new Exception();
}
} else {
// There are no tasks on the activity stack, meaning no activities are in the foreground.
// Thus, opening the app from start
Intent intent = new Intent(this, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
} catch (Exception e) {
Intent intent = new Intent(this, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
});
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String appName = intent.getStringExtra(BLOCKED_APP_NAME);
textView = findViewById(R.id.block_app_text);
if (textView != null && appName != null){
textView.setText(appName + " is blocked by SimpliTend");
}
}
@Override
public void onBackPressed() {
// super.onBackPressed();
}
}

View File

@@ -41,6 +41,7 @@ public class FUAActivity extends AppCompatActivity {
TextView all_apps_title;
LinearLayout no_fua;
TextView no_fua_txt;
List<AppList> installed_app_list;
@@ -59,6 +60,7 @@ public class FUAActivity extends AppCompatActivity {
rvWhiteApps = (RecyclerView) findViewById(R.id.rv_white_apps);
mySharedPref = new MySharedPref(FUAActivity.this);
no_fua = findViewById(R.id.no_fua);
no_fua_txt = findViewById(R.id.no_fua_text);
all_apps_title = findViewById(R.id.all_app_tile);
if (!isAccessibilityAppBlockingEnabled()) {
@@ -96,6 +98,7 @@ public class FUAActivity extends AppCompatActivity {
if (!isFromDashboard) {
// from settings page
no_fua_txt.setText(R.string.no_frequently_used_apps);
rvApps.setVisibility(View.VISIBLE);
all_apps_title.setVisibility(View.VISIBLE);
findViewById(R.id.done_btn).setVisibility(View.VISIBLE);
@@ -123,6 +126,8 @@ public class FUAActivity extends AppCompatActivity {
rvApps.setAdapter(adapter);
} else {
// from dashboard
no_fua_txt.setText(R.string.no_frequently_used_apps_set_up);
rvApps.setVisibility(View.GONE);
all_apps_title.setVisibility(View.GONE);
findViewById(R.id.done_btn).setVisibility(View.GONE);

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import android.os.Build;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
import com.app.simplitend.BuildConfig;
@@ -13,6 +14,7 @@ import java.util.ArrayList;
import java.util.List;
public class TopAppDetectionService extends AccessibilityService {
public static final String BLOCKED_APP_NAME = "BLOCKED_APP_NAME";
MySharedPref sharedPref;
List<String> appsList = new ArrayList<>();
@@ -40,7 +42,17 @@ public class TopAppDetectionService extends AccessibilityService {
if (sharedPref.getArrayList("APP_LIST").contains(packageName)) {
Intent intent = new Intent(this, BlockApp.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String appName;
try {
String[] split_name = packageName.split("\\.");
appName = split_name[split_name.length-1].toUpperCase();
}catch (Exception e){
appName = "This app";
}
intent.putExtra(BLOCKED_APP_NAME, appName);
startActivity(intent);
Toast.makeText(this, appName + " is blocked by SimpliTend", Toast.LENGTH_SHORT).show();
}
}

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z"/>
</vector>

View File

@@ -72,6 +72,7 @@
/>
<TextView
android:id="@+id/no_fua_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@@ -1,20 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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:background="@color/black">
android:orientation="vertical"
android:gravity="center"
android:background="@color/white">
<TextView
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App blocked"
android:textColor="@color/white"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
>
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:scaleType="fitXY"
android:src="@drawable/ic_shield"
app:tint="@color/color_primary_dark" />
<ImageView
android:layout_width="@dimen/_40sdp"
android:layout_height="@dimen/_40sdp"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:src="@drawable/iic_dnd"
app:tint="@color/white" />
</RelativeLayout>
<TextView
android:id="@+id/block_app_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/this_app_is_blocked_by_simplitend"
android:fontFamily="@font/nunito_bold"
android:textColor="@color/black"
android:textAppearance="@style/TextAppearance.Material3.TitleLarge"
android:layout_marginHorizontal="15dp"
android:textAlignment="center"
android:layout_marginTop="15dp"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/open_simplitent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_simplitend"
android:fontFamily="@font/nunito_bold"
android:textColor="@color/white"
android:textAllCaps="true"
android:layout_marginTop="15dp"
app:backgroundTint="@color/color_primary_dark"
app:cornerRadius="5dp"
/>
</LinearLayout>

View File

@@ -420,6 +420,7 @@
<string name="select_number_to_cal_or_message">Select number to cal or message</string>
<string name="call">Call</string>
<string name="no_frequently_used_apps">No frequently used apps added\nPlease select an app from below list to unlock.</string>
<string name="no_frequently_used_apps_set_up">No frequently used apps added\nGoto Profile -> Frequently used apps to setup this feature.</string>
<string name="refresh">refresh</string>
<string name="illustration">illustration</string>
<string name="privacy_policy">Privacy Policy</string>
@@ -439,5 +440,8 @@
<string name="patient_geofence">Geofence</string>
<string name="swipe_down">Swipe down</string>
<string name="direction_requests">Direction Requests</string>
<string name="testing_view">Testing View</string>
<string name="this_app_is_blocked_by_simplitend">This app is blocked by SimpliTend</string>
<string name="open_simplitend">open simplitend</string>
</resources>