dialog to enable notification access

This commit is contained in:
danijoo
2016-01-02 14:40:06 +01:00
parent dec245e12b
commit e91f4c86bc
4 changed files with 50 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import android.view.MenuItem;
import android.view.View;
import net.headlezz.notificationlogger.createnotification.NotificationCreationFragment;
import net.headlezz.notificationlogger.logger.LoggerUtils;
import net.headlezz.notificationlogger.presenter.LoggerWarningPresenter;
import butterknife.Bind;
@@ -59,6 +60,8 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
@Override
protected void onResume() {
super.onResume();
if(!LoggerUtils.isLoggerRunning())
LoggerUtils.buildNotificationAccessDialog(this).show();
if(getSupportFragmentManager().getBackStackEntryCount() > 0)
mFAB.setVisibility(View.GONE);
}

View File

@@ -0,0 +1,36 @@
package net.headlezz.notificationlogger.logger;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import net.headlezz.notificationlogger.R;
public class LoggerUtils {
public static void openNotificationSystemSettings(Context context) {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
context.startActivity(intent);
}
public static boolean isLoggerRunning() {
return NotificationLoggerService.isRunning;
}
public static AlertDialog buildNotificationAccessDialog(final Context context) {
return new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.main_dialog_enable_notification_access_title))
.setMessage(context.getString(R.string.main_dialog_enable_notification_access_message))
.setPositiveButton(R.string.main_dialog_enable_notification_access_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
openNotificationSystemSettings(context);
}
})
.setNegativeButton(R.string.main_dialog_enable_notification_access_negative, null)
.create();
}
}

View File

@@ -18,7 +18,14 @@ import timber.log.Timber;
public class NotificationLoggerService extends NotificationListenerService implements SharedPreferences.OnSharedPreferenceChangeListener {
/**
* true if logger is enabled in system settings
*/
public static boolean isRunning = false;
/**
* true if logger is enabled in app settings
*/
public static boolean isEnabled = true;
SharedPreferences mSharedPrefs;

View File

@@ -5,6 +5,10 @@
<string name="main_snack_logging_disabled_warning">Logging is disabled.</string>
<string name="main_snack_logging_disabled_warning_action">Enable</string>
<string name="main_dialog_enable_notification_access_title">Enable Notification Access</string>
<string name="main_dialog_enable_notification_access_message">In order to log notifcations, this app needs access to your notification system.</string>
<string name="main_dialog_enable_notification_access_positive">Open settings</string>
<string name="main_dialog_enable_notification_access_negative">Cancel</string>
<string name="pref_category_notification_settings">Notification Settings</string>
<string name="pref_category_support">Support</string>