-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b1d1f4
commit cd5ef26
Showing
11 changed files
with
490 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 91 additions & 144 deletions
235
app/src/main/java/protect/card_locker/ImportExportActivity.java
Large diffs are not rendered by default.
Oops, something went wrong.
143 changes: 0 additions & 143 deletions
143
app/src/main/java/protect/card_locker/ImportExportTask.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/protect/card_locker/NotificationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package protect.card_locker; | ||
|
||
import static android.content.Context.NOTIFICATION_SERVICE; | ||
|
||
import android.app.Notification; | ||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class NotificationHelper { | ||
|
||
// Do not change these IDs! | ||
public static final String CHANNEL_IMPORT = "import"; | ||
|
||
public static final String CHANNEL_EXPORT = "export"; | ||
|
||
public static final int IMPORT_ID = 100; | ||
public static final int IMPORT_PROGRESS_ID = 101; | ||
public static final int EXPORT_ID = 103; | ||
public static final int EXPORT_PROGRESS_ID = 104; | ||
|
||
|
||
public static Notification.Builder createNotificationBuilder(@NonNull Context context, @NonNull String channel, @NonNull int icon, @NonNull String title, @Nullable String message) { | ||
Notification.Builder notificationBuilder = new Notification.Builder(context) | ||
.setSmallIcon(icon) | ||
.setTicker(title) | ||
.setContentTitle(title); | ||
|
||
if (message != null) { | ||
notificationBuilder.setContentText(message); | ||
} | ||
|
||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | ||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); | ||
NotificationChannel notificationChannel = new NotificationChannel(channel, getChannelName(channel), NotificationManager.IMPORTANCE_DEFAULT); | ||
notificationManager.createNotificationChannel(notificationChannel); | ||
|
||
notificationBuilder.setChannelId(channel); | ||
} | ||
|
||
return notificationBuilder; | ||
} | ||
|
||
public static void sendNotification(@NonNull Context context, @NonNull int notificationId, @NonNull Notification notification) { | ||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); | ||
|
||
notificationManager.notify(notificationId, notification); | ||
} | ||
|
||
private static String getChannelName(@NonNull String channel) { | ||
switch(channel) { | ||
case CHANNEL_IMPORT: | ||
return "Import"; | ||
case CHANNEL_EXPORT: | ||
return "Export"; | ||
default: | ||
throw new IllegalArgumentException("Unknown notification channel"); | ||
} | ||
} | ||
} |
Oops, something went wrong.