Add a switch to disable notifications
This commit is contained in:
parent
19f640c528
commit
d33d881834
|
@ -1,8 +1,10 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -17,6 +19,20 @@ public class CallReceiver extends BroadcastReceiver {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CallReceiver.class);
|
||||
|
||||
public static boolean isEnabled(Context context) {
|
||||
return context.getPackageManager()
|
||||
.getComponentEnabledSetting(new ComponentName(context, CallReceiver.class))
|
||||
!= PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
}
|
||||
|
||||
public static void setEnabled(Context context, boolean enable) {
|
||||
context.getPackageManager().setComponentEnabledSetting(
|
||||
new ComponentName(context, CallReceiver.class),
|
||||
enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
// TODO: handle in-call calls
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package dummydomain.yetanothercallblocker;
|
|||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -14,6 +15,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
SwitchCompat notificationsSwitch = findViewById(R.id.notificationsEnabledSwitch);
|
||||
notificationsSwitch.setChecked(CallReceiver.isEnabled(this));
|
||||
notificationsSwitch.setOnCheckedChangeListener((buttonView, isChecked)
|
||||
-> CallReceiver.setEnabled(MainActivity.this, isChecked));
|
||||
|
||||
PermissionHelper.checkPermissions(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/text_margin"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/notificationsEnabledSwitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/incoming_call_notifications_enabled" />
|
||||
</LinearLayout>
|
|
@ -40,6 +40,9 @@
|
|||
<string name="sia_category_safe_nonprofit">Safe nonprofit</string>
|
||||
|
||||
<string name="title_activity_reviews">Reviews</string>
|
||||
|
||||
<string name="incoming_call_notifications_enabled">Incoming call notifications enabled</string>
|
||||
|
||||
<string name="open_debug_activity">Open debug screen</string>
|
||||
<string name="debug_activity_label">Debug</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue