1+ package eu .faircode .netguard ;
2+
3+ import android .content .BroadcastReceiver ;
4+ import android .content .Context ;
5+ import android .content .Intent ;
6+ import android .content .SharedPreferences ;
7+ import android .widget .Toast ;
8+
9+ import androidx .preference .PreferenceManager ;
10+
11+ import net .kollnig .missioncontrol .R ;
12+
13+ public class ReceiverShortcut extends BroadcastReceiver {
14+
15+ @ Override
16+ public void onReceive (Context context , Intent intent ) {
17+ String action = intent .getAction ();
18+ String nextAction = null ;
19+ String message = null ;
20+
21+ if ("eu.faircode.netguard.SHORTCUT_ON" .equals (action )) {
22+ nextAction = WidgetAdmin .INTENT_ON ;
23+ message = context .getString (R .string .shortcut_on );
24+ } else if ("eu.faircode.netguard.SHORTCUT_OFF" .equals (action )) {
25+ nextAction = WidgetAdmin .INTENT_OFF ;
26+ message = context .getString (R .string .shortcut_off );
27+ } else {
28+ // Fallback to toggle if needed
29+ SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (context );
30+ boolean enabled = prefs .getBoolean ("enabled" , false );
31+ nextAction = (enabled ? WidgetAdmin .INTENT_OFF : WidgetAdmin .INTENT_ON );
32+ message = context .getString (enabled ? R .string .shortcut_off : R .string .shortcut_on );
33+ }
34+
35+ if (nextAction != null ) {
36+ Intent toggleIntent = new Intent (nextAction );
37+ toggleIntent .setPackage (context .getPackageName ());
38+ context .sendBroadcast (toggleIntent );
39+
40+ if (message != null ) {
41+ Toast .makeText (context , message , Toast .LENGTH_SHORT ).show ();
42+ }
43+ }
44+ }
45+ }
0 commit comments