Skip to content

Commit d910431

Browse files
committed
Project Refactored
1 parent 434018b commit d910431

34 files changed

+146
-178
lines changed

app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
33
android {
44
compileSdkVersion 29
55
defaultConfig {
6-
applicationId "com.willme.topactivity"
6+
applicationId "com.ratul.topactivity"
77
minSdkVersion 14
88
targetSdkVersion 25
99
versionCode 15
@@ -26,6 +26,5 @@ android {
2626
}
2727

2828
dependencies {
29-
//api project(':FancyDialog')
3029
implementation 'com.android.support:support-v4:25.4.0'
3130
}

app/proguard-rules.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Use Default
1+

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.willme.topactivity">
3+
package="com.ratul.topactivity">
44
<!-- Ask to ignore battery optimizations -->
55
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
66
<!-- Retrieve running apps -->
@@ -49,7 +49,7 @@
4949
android:exported="true" />
5050

5151
<activity
52-
android:name=".AppShortcutsActivity"
52+
android:name=".ShortcutHandlerActivity"
5353
android:excludeFromRecents="true"
5454
android:enabled="true"
5555
android:exported="true"
@@ -63,17 +63,14 @@
6363
android:theme="@style/TransparentTheme"/>
6464

6565
<service
66-
android:name=".WatchingService"
67-
android:enabled="@bool/use_watching_service"
66+
android:name=".MonitoringService"
67+
android:enabled="true"
6868
android:exported="false"/>
6969

7070
<service
71-
android:name=".ProcessMonitor"
72-
android:enabled="@bool/use_process_monitor"
73-
android:exported="false"/>
74-
<service
75-
android:name=".WatchingAccessibilityService"
76-
android:label="@string/accessibility_permission"
71+
android:name=".AccessibilityWatcher"
72+
android:label="@string/app_name"
73+
android:description="@string/accessibility_permission"
7774
android:enabled="@bool/use_accessibility_service"
7875
android:exported="false"
7976
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
@@ -86,9 +83,9 @@
8683
android:resource="@xml/accessibility"/>
8784
</service>
8885
<service
89-
android:name=".QuickSettingTileService"
90-
android:enabled="@bool/qs_tile_service_availability"
91-
android:icon="@drawable/ic_notification"
86+
android:name=".QuickSettingsService"
87+
android:enabled="@bool/quick_settings_availability"
88+
android:icon="@drawable/ic_shortcut"
9289
android:label="@string/app_name"
9390
android:exported="false"
9491
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
@@ -102,11 +99,11 @@
10299
</service>
103100

104101
<receiver
105-
android:name=".NotificationActionReceiver"
102+
android:name=".NotificationMonitor"
106103
android:exported="false"
107104
android:enabled="true">
108105
<intent-filter>
109-
<action android:name="com.willme.topactivity.ACTION_NOTIFICATION_RECEIVER"/>
106+
<action android:name="com.ratul.topactivity.ACTION_NOTIFICATION_RECEIVER"/>
110107
</intent-filter>
111108
</receiver>
112109
</application>

app/src/main/java/com/ratul/fancy/FancyDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import android.view.View.OnClickListener;
2525
import android.graphics.drawable.*;
2626
import android.content.res.*;
27-
import com.willme.topactivity.R;
27+
import com.ratul.topactivity.R;
2828

2929
/**
3030
* Created by Ratul on 04/05/2022.

app/src/main/java/com/willme/topactivity/WatchingAccessibilityService.java renamed to app/src/main/java/com/ratul/topactivity/AccessibilityWatcher.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
17-
package com.willme.topactivity;
17+
package com.ratul.topactivity;
1818

1919
import android.accessibilityservice.AccessibilityService;
2020
import android.annotation.SuppressLint;
@@ -26,35 +26,29 @@
2626
* Created by Wen on 16/02/2017.
2727
* Refactored by Ratul on 04/05/2022.
2828
*/
29-
public class WatchingAccessibilityService extends AccessibilityService {
30-
private static WatchingAccessibilityService sInstance;
29+
public class AccessibilityWatcher extends AccessibilityService {
30+
private static AccessibilityWatcher sInstance;
3131

32-
public static WatchingAccessibilityService getInstance() {
32+
public static AccessibilityWatcher getInstance() {
3333
return sInstance;
3434
}
3535

3636
@Override
3737
public void onAccessibilityEvent(AccessibilityEvent event) {
38-
if (TasksWindow.viewAdded && SPHelper.isShowWindow(this) && SPHelper.hasAccess(this)) {
38+
if (WindowUtility.viewAdded && SharedPrefsUtil.isShowWindow(this) && SharedPrefsUtil.hasAccess(this)) {
3939
String act1 = event.getClassName().toString();
4040
String act2 = event.getPackageName().toString();
4141

4242
if (act1 == null || act1.trim().isEmpty())
4343
return;
44-
TasksWindow.show(this, act2, act1);
44+
WindowUtility.show(this, act2, act1);
4545
}
4646
}
4747

4848
@Override
4949
public void onInterrupt() {
5050
}
5151

52-
@Override
53-
public int onStartCommand(Intent intent, int flags, int startId) {
54-
sInstance = this;
55-
return super.onStartCommand(intent, flags, startId);
56-
}
57-
5852
@Override
5953
protected void onServiceConnected() {
6054
sInstance = this;
@@ -64,9 +58,9 @@ protected void onServiceConnected() {
6458
@Override
6559
public boolean onUnbind(Intent intent) {
6660
sInstance = null;
67-
TasksWindow.dismiss(this);
68-
NotificationActionReceiver.cancelNotification(this);
69-
sendBroadcast(new Intent(QuickSettingTileService.ACTION_UPDATE_TITLE));
61+
WindowUtility.dismiss(this);
62+
NotificationMonitor.cancelNotification(this);
63+
sendBroadcast(new Intent(QuickSettingsService.ACTION_UPDATE_TITLE));
7064
return super.onUnbind(intent);
7165
}
7266
}

app/src/main/java/com/willme/topactivity/BackgroundActivity.java renamed to app/src/main/java/com/ratul/topactivity/BackgroundActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
17-
package com.willme.topactivity;
17+
package com.ratul.topactivity;
1818

1919
import android.annotation.TargetApi;
2020
import android.app.Activity;
@@ -31,7 +31,7 @@
3131
*/
3232
@TargetApi(29)
3333
public class BackgroundActivity extends Activity {
34-
public static String STRING_COPY = "com.willme.topactivity.COPY_STRING";
34+
public static String STRING_COPY = "com.ratul.topactivity.COPY_STRING";
3535

3636
@Override
3737
protected void onCreate(@Nullable Bundle savedInstanceState) {

app/src/main/java/com/willme/topactivity/MainActivity.java renamed to app/src/main/java/com/ratul/topactivity/MainActivity.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
17-
package com.willme.topactivity;
17+
package com.ratul.topactivity;
1818

1919
import android.app.*;
2020
import android.content.*;
@@ -43,7 +43,7 @@
4343

4444
public class MainActivity extends Activity implements OnCheckedChangeListener {
4545
public static final String EXTRA_FROM_QS_TILE = "from_qs_tile";
46-
public static final String ACTION_STATE_CHANGED = "com.willme.topactivity.ACTION_STATE_CHANGED";
46+
public static final String ACTION_STATE_CHANGED = "com.ratul.topactivity.ACTION_STATE_CHANGED";
4747
CompoundButton mWindowSwitch, mNotificationSwitch, mAccessibilitySwitch;
4848
private BroadcastReceiver mReceiver;
4949
private int theme;
@@ -53,13 +53,14 @@ public class MainActivity extends Activity implements OnCheckedChangeListener {
5353
protected void onPostCreate(Bundle savedInstanceState) {
5454
super.onPostCreate(savedInstanceState);
5555
INSTANCE = this;
56-
if (WatchingAccessibilityService.getInstance() == null && SPHelper.hasAccess(this))
57-
startService(new Intent().setClass(this, WatchingAccessibilityService.class));
56+
if (AccessibilityWatcher.getInstance() == null && SharedPrefsUtil.hasAccess(this))
57+
startService(new Intent().setClass(this, AccessibilityWatcher.class));
5858
}
5959

6060
@Override
6161
protected void onCreate(Bundle savedInstanceState) {
6262
super.onCreate(savedInstanceState);
63+
6364
setContentView(R.layout.activity_main);
6465
theme = FancyDialog.DARK_THEME;
6566
ColorSetup.setupColors(this, theme);
@@ -80,22 +81,21 @@ protected void onCreate(Bundle savedInstanceState) {
8081
showWindow.setTextColor(ColorSetup.messageColor);
8182
disableNltification.setTextColor(ColorSetup.messageColor);
8283

83-
mWindowSwitch = (CompoundButton) findViewById(R.id.sw_window);
84+
mWindowSwitch = findViewById(R.id.sw_window);
8485
mWindowSwitch.setOnCheckedChangeListener(this);
8586
if (Build.VERSION.SDK_INT < 24) {
8687
findViewById(R.id.useNotificationPref).setVisibility(View.GONE);
8788
findViewById(R.id.divider_useNotificationPref).setVisibility(View.GONE);
8889
}
8990
if (Build.VERSION.SDK_INT < 21) {
90-
SPHelper.setHasAccess(this, false);
9191
findViewById(R.id.useAccessibility).setVisibility(View.GONE);
9292
findViewById(R.id.divider_useAccess).setVisibility(View.GONE);
9393
}
94-
mNotificationSwitch = (CompoundButton) findViewById(R.id.sw_notification);
94+
mNotificationSwitch = findViewById(R.id.sw_notification);
9595
if (mNotificationSwitch != null) {
9696
mNotificationSwitch.setOnCheckedChangeListener(this);
9797
}
98-
mAccessibilitySwitch = (CompoundButton) findViewById(R.id.sw_accessibility);
98+
mAccessibilitySwitch = findViewById(R.id.sw_accessibility);
9999
if (mAccessibilitySwitch != null) {
100100
mAccessibilitySwitch.setOnCheckedChangeListener(this);
101101
}
@@ -120,35 +120,35 @@ protected void onResume() {
120120
refreshWindowSwitch();
121121
refreshNotificationSwitch();
122122
refreshAccessibilitySwitch();
123-
NotificationActionReceiver.cancelNotification(this);
123+
NotificationMonitor.cancelNotification(this);
124124
}
125125

126126
@Override
127127
protected void onPause() {
128128
super.onPause();
129-
if (SPHelper.isShowWindow(this)) {
130-
NotificationActionReceiver.showNotification(this, false);
129+
if (SharedPrefsUtil.isShowWindow(this)) {
130+
NotificationMonitor.showNotification(this, false);
131131
}
132132
}
133133

134134
private void refreshWindowSwitch() {
135-
mWindowSwitch.setChecked(SPHelper.isShowWindow(this));
135+
mWindowSwitch.setChecked(SharedPrefsUtil.isShowWindow(this));
136136
if (getResources().getBoolean(R.bool.use_accessibility_service)) {
137-
if (SPHelper.hasAccess(this) && WatchingAccessibilityService.getInstance() == null) {
137+
if (SharedPrefsUtil.hasAccess(this) && AccessibilityWatcher.getInstance() == null) {
138138
mWindowSwitch.setChecked(false);
139139
}
140140
}
141141
}
142142

143143
private void refreshAccessibilitySwitch() {
144144
if (mAccessibilitySwitch != null) {
145-
mAccessibilitySwitch.setChecked(SPHelper.hasAccess(this));
145+
mAccessibilitySwitch.setChecked(SharedPrefsUtil.hasAccess(this));
146146
}
147147
}
148148

149149
private void refreshNotificationSwitch() {
150150
if (mNotificationSwitch != null) {
151-
mNotificationSwitch.setChecked(!SPHelper.isNotificationToggleEnabled(this));
151+
mNotificationSwitch.setChecked(!SharedPrefsUtil.isNotificationToggleEnabled(this));
152152
}
153153
}
154154

@@ -180,7 +180,7 @@ public void onClick(View v) {
180180
fancy.show();
181181
} else if (title.equals("GitHub Repo")) {
182182
fancy.setTitle("GitHub Repo");
183-
fancy.setMessage("Would you like to visit the official github repo of this app");
183+
fancy.setMessage("It is an open source project. Would you like to visit the official github repo of this app");
184184
fancy.setPositiveButton("Yes", new View.OnClickListener() {
185185
@Override
186186
public void onClick(View v) {
@@ -203,21 +203,21 @@ public void onClick(View v) {
203203
@Override
204204
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
205205
if (buttonView == mNotificationSwitch) {
206-
SPHelper.setNotificationToggleEnabled(this, !isChecked);
206+
SharedPrefsUtil.setNotificationToggleEnabled(this, !isChecked);
207207
buttonView.setChecked(isChecked);
208208
return;
209209
}
210210
if (buttonView == mAccessibilitySwitch) {
211-
SPHelper.setHasAccess(this, isChecked);
211+
SharedPrefsUtil.setHasAccess(this, isChecked);
212212
buttonView.setChecked(isChecked);
213-
if(isChecked && WatchingAccessibilityService.getInstance() == null)
214-
startService(new Intent().setClass(this, WatchingAccessibilityService.class));
213+
if(isChecked && AccessibilityWatcher.getInstance() == null)
214+
startService(new Intent().setClass(this, AccessibilityWatcher.class));
215215
return;
216216
}
217217
if (isChecked && buttonView == mWindowSwitch && Build.VERSION.SDK_INT >= 21) {
218218
if (Build.VERSION.SDK_INT >= 29 && !((PowerManager) getSystemService("power")).isIgnoringBatteryOptimizations(getPackageName())) {
219219
setupBattery();
220-
SPHelper.setHasBattery(this, true);
220+
SharedPrefsUtil.setHasBattery(this, true);
221221
return;
222222
}
223223
if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
@@ -244,7 +244,7 @@ public void onClick(View view) {
244244
onCheckedChanged(buttonView, false);
245245
return;
246246
}
247-
if (SPHelper.hasAccess(this) && WatchingAccessibilityService.getInstance() == null) {
247+
if (SharedPrefsUtil.hasAccess(this) && AccessibilityWatcher.getInstance() == null) {
248248
final FancyDialog fancy = new FancyDialog(MainActivity.this, theme);
249249
fancy.setTitle("Accessibility Permission");
250250
fancy.setMessage("Enable my Accessibility Service in order to get current activity info");
@@ -261,15 +261,15 @@ public void onClick(View view) {
261261
fancy.setNegativeButton("Close", new View.OnClickListener() {
262262
@Override
263263
public void onClick(View view) {
264-
SPHelper.setHasAccess(MainActivity.this, false);
264+
SharedPrefsUtil.setHasAccess(MainActivity.this, false);
265265
fancy.dismiss();
266266
}
267267
});
268268
fancy.show();
269269
onCheckedChanged(buttonView, false);
270270
return;
271271
}
272-
if (!usageStats(MainActivity.this) && getResources().getBoolean(R.bool.use_watching_service)) {
272+
if (!usageStats(MainActivity.this)) {
273273
final FancyDialog fancy = new FancyDialog(MainActivity.this, theme);
274274
fancy.setTitle("Usage Access");
275275
fancy.setMessage("Enable my Usage Access permission in order to get current activity info");
@@ -295,13 +295,13 @@ public void onClick(View view) {
295295
}
296296
}
297297
if (buttonView == mWindowSwitch) {
298-
SPHelper.setAppInitiated(this, true);
299-
SPHelper.setIsShowWindow(this, isChecked);
298+
SharedPrefsUtil.setAppInitiated(this, true);
299+
SharedPrefsUtil.setIsShowWindow(this, isChecked);
300300
if (!isChecked) {
301-
TasksWindow.dismiss(this);
301+
WindowUtility.dismiss(this);
302302
} else {
303-
TasksWindow.show(this, getPackageName(), getClass().getName());
304-
startService(new Intent(this, WatchingService.class));
303+
WindowUtility.show(this, getPackageName(), getClass().getName());
304+
startService(new Intent(this, MonitoringService.class));
305305
}
306306
}
307307
}

0 commit comments

Comments
 (0)