.
This commit is contained in:
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user