Notification details dialog
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package net.headlezz.notificationlogger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.headlezz.notificationlogger.logger.LoggedNotification;
|
||||
|
||||
public class NotificationInfoDialog extends AlertDialog implements DialogInterface.OnClickListener {
|
||||
|
||||
LoggedNotification mNotification;
|
||||
|
||||
public NotificationInfoDialog(Context context, LoggedNotification notification) {
|
||||
super(context);
|
||||
mNotification = notification;
|
||||
|
||||
setTitle(notification.appName);
|
||||
setIcon(PackageUtils.getApplicationLauncherIcon(context, notification.packageName));
|
||||
setMessage(getDialogContent());
|
||||
setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.main_notification_details_button_ok), this);
|
||||
setButton(AlertDialog.BUTTON_NEUTRAL, context.getString(R.string.main_notification_details_button_app_info), this);
|
||||
}
|
||||
|
||||
private Spanned getDialogContent() {
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
contentBuilder.append(getContext().getString(R.string.main_notification_details_package, mNotification.packageName));
|
||||
contentBuilder.append("<br />");
|
||||
contentBuilder.append(getContext().getString(R.string.main_notification_details_date,
|
||||
9999));
|
||||
contentBuilder.append("<br />");
|
||||
contentBuilder.append(getContext().getString(R.string.main_notification_details_userid, mNotification.userId));
|
||||
contentBuilder.append("<br />");
|
||||
contentBuilder.append("<br />");
|
||||
contentBuilder.append(getContext().getString(R.string.main_notification_details_title, mNotification.title));
|
||||
contentBuilder.append("<br />");
|
||||
contentBuilder.append(getContext().getString(R.string.main_notification_details_message, mNotification.message));
|
||||
return Html.fromHtml(contentBuilder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if(which == AlertDialog.BUTTON_NEUTRAL) {
|
||||
if(!PackageUtils.showAppInfoActivity(getContext(), mNotification.packageName))
|
||||
Toast.makeText(getContext(), R.string.notification_info_dialog_app_info_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package net.headlezz.notificationlogger;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
@@ -49,5 +52,21 @@ public class PackageUtils {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param packageName
|
||||
* @return true if application settings opened successful
|
||||
*/
|
||||
public static boolean showAppInfoActivity(Context context, String packageName) {
|
||||
try {
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch ( ActivityNotFoundException e ) {
|
||||
Timber.e("Failed to open app info", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.headlezz.notificationlogger.NotificationInfoDialog;
|
||||
import net.headlezz.notificationlogger.R;
|
||||
import net.headlezz.notificationlogger.logger.LoggedNotification;
|
||||
import net.headlezz.notificationlogger.logger.Logged_notificationTable;
|
||||
@@ -96,5 +97,7 @@ public class NotificationListFragment extends Fragment implements LoaderManager.
|
||||
Cursor cursor = getContext().getContentResolver().query(Logged_notificationTable.CONTENT_URI, null, qry, args, null);
|
||||
LoggedNotification notification = Logged_notificationTable.getRow(cursor, true);
|
||||
Timber.e(notification.title);
|
||||
|
||||
new NotificationInfoDialog(getContext(), notification).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
<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="main_notification_details_package"><b>Package:</b> %1$s</string>
|
||||
<string name="main_notification_details_date"><b>Date:</b> %1$s</string>
|
||||
<string name="main_notification_details_userid"><b>User ID:</b> %1$s</string>
|
||||
<string name="main_notification_details_title"><b>Title:</b> %1$s</string>
|
||||
<string name="main_notification_details_message"><b>Message:</b> %1$s</string>
|
||||
<string name="main_notification_details_button_app_info">App Info</string>
|
||||
<string name="main_notification_details_button_ok">OK</string>
|
||||
|
||||
<string name="pref_category_notification_settings">Notification Settings</string>
|
||||
<string name="pref_category_support">Support</string>
|
||||
@@ -47,6 +54,7 @@
|
||||
<string name="notification_list_empty">No notifications found.</string>
|
||||
<string name="notification_small_icon_cd">Notification small icon</string>
|
||||
<string name="app_icon_cd">Application icon for %s</string>
|
||||
<string name="notification_info_dialog_app_info_error">Failed to display app info.</string>
|
||||
|
||||
<string-array name="create_categories">
|
||||
<item>Alarm</item>
|
||||
|
||||
Reference in New Issue
Block a user