├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── raw
│ │ │ └── sound.mp3
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ └── layout
│ │ │ └── sample_activity.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── ir
│ │ └── zadak
│ │ └── notification
│ │ └── Sample.java
├── proguard-rules.pro
└── build.gradle
├── zadaknotify
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-nodpi
│ │ │ └── ic_placeholder.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ └── notification_custom.xml
│ │ ├── java
│ │ └── ir
│ │ │ └── zadak
│ │ │ └── zadaknotify
│ │ │ ├── interfaces
│ │ │ ├── OnImageLoadingCompleted.java
│ │ │ ├── ImageLoader.java
│ │ │ └── PendingIntentNotification.java
│ │ │ ├── constants
│ │ │ └── BroadcastActions.java
│ │ │ ├── notification
│ │ │ ├── Simple.java
│ │ │ ├── Progress.java
│ │ │ ├── Builder.java
│ │ │ ├── ZadakNotification.java
│ │ │ ├── Custom.java
│ │ │ ├── Wear.java
│ │ │ └── Load.java
│ │ │ ├── pendingintent
│ │ │ ├── ClickPendingIntentBroadCast.java
│ │ │ ├── DismissPendingIntentBroadCast.java
│ │ │ ├── ClickPendingIntentActivity.java
│ │ │ └── DismissPendingIntentActivity.java
│ │ │ └── model
│ │ │ └── NotificationBean.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── encodings.xml
├── vcs.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── .github
└── workflows
│ └── android.yml
├── gradle.properties
├── LICENSE
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/zadaknotify/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':zadaknotify'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/sound.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/raw/sound.mp3
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/zadaknotify/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/drawable-nodpi/ic_placeholder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehrdadsafari/ZadakNotification/HEAD/zadaknotify/src/main/res/drawable-nodpi/ic_placeholder.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #CC2f2f2f
4 | #FFFFFF
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 18sp
4 | 14sp
5 | 8dp
6 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/interfaces/OnImageLoadingCompleted.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.interfaces;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public interface OnImageLoadingCompleted {
6 |
7 | void imageLoadingCompleted(Bitmap bitmap);
8 | }
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 04 13:31:44 IRDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/interfaces/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.interfaces;
2 |
3 | public interface ImageLoader {
4 | void load(String uri, OnImageLoadingCompleted onCompleted);
5 |
6 | void load(int imageResId, OnImageLoadingCompleted onCompleted);
7 | }
8 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/interfaces/PendingIntentNotification.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.interfaces;
2 |
3 | import android.app.PendingIntent;
4 |
5 | public interface PendingIntentNotification {
6 |
7 | public PendingIntent onSettingPendingIntent();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/constants/BroadcastActions.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.constants;
2 |
3 | public class BroadcastActions {
4 | public static final String ACTION_CLICK_INTENT = "ir.zadak.zadaknotify.action.click.intent";
5 | public static final String ACTION_DISMISS_INTENT = "ir.zadak.zadaknotify.action.dismiss.intent";
6 | }
7 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v1
12 | - name: set up JDK 1.8
13 | uses: actions/setup-java@v1
14 | with:
15 | java-version: 1.8
16 | - name: Build with Gradle
17 | run: ./gradlew build
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Simple.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.support.v4.app.NotificationCompat;
4 |
5 | public class Simple extends Builder {
6 | public Simple(NotificationCompat.Builder builder, int identifier, String tag) {
7 | super(builder, identifier, tag);
8 | }
9 |
10 | @Override
11 | public void build() {
12 | super.build();
13 | super.notificationNotify();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/zadaknotify/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support:appcompat-v7:28.0.0'
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 12sp
5 | 14sp
6 | 18sp
7 | 22sp
8 | 35sp
9 | 60sp
10 |
11 |
12 |
13 | 2dp
14 | 4dp
15 | 8dp
16 | 12dp
17 | 16dp
18 | 20dp
19 | 24dp
20 |
21 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ZadakNotify
3 | Notification
4 | Notification Custom
5 | Title
6 | Message
7 | Small Icon
8 | Background
9 | extra_voice_reply
10 | Reply
11 |
12 | - Yes
13 | - No
14 | - Maybe
15 |
16 |
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/zadaknotify/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "ir.zadak.notification"
7 | minSdkVersion 16
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | repositories {
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | //noinspection GradleCompatible
27 | implementation 'com.android.support:appcompat-v7:28.0.0'
28 | implementation 'com.github.mehrdadsafari:ZadakNotification:0.0.2'
29 | implementation 'com.squareup.picasso:picasso:2.71828'
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Progress.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.support.v4.app.NotificationCompat;
4 |
5 | public class Progress extends Builder {
6 | public Progress(NotificationCompat.Builder builder, int identifier, String tag) {
7 | super(builder, identifier, tag);
8 | }
9 |
10 | @Override
11 | public void build() {
12 | super.build();
13 | super.notificationNotify();
14 | }
15 |
16 | public Progress update(int identifier, int progress, int max, boolean indeterminate) {
17 | NotificationCompat.Builder builder = new NotificationCompat.Builder(ZadakNotification.mSingleton.mContext);
18 | builder.setProgress(max, progress, indeterminate);
19 |
20 | notification = builder.build();
21 | notificationNotify(identifier);
22 | return this;
23 | }
24 |
25 | public Progress value(int progress, int max, boolean indeterminate) {
26 | builder.setProgress(max, progress, indeterminate);
27 | return this;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Mehrdad Safari
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ZadakNotification
3 |
4 | Type
5 | The fields can\'t be empty!
6 |
7 |
8 | Title
9 | Insert Title
10 | Message
11 | Big Text
12 | Url Image
13 | Url
14 | Big Text
15 | Insert Message
16 | Notify Simple
17 | Notify Custom
18 | 5 new messages
19 |
20 |
21 | - Simple
22 | - Big Text
23 | - Inbox Style
24 |
25 |
26 |
27 | - Message 1
28 | - Message 2
29 | - Message 3
30 | - Message 4
31 | - Message 5
32 |
33 |
34 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/pendingintent/ClickPendingIntentBroadCast.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.pendingintent;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 |
7 | import ir.zadak.zadaknotify.constants.BroadcastActions;
8 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
9 | import ir.zadak.zadaknotify.notification.ZadakNotification;
10 |
11 |
12 | public class ClickPendingIntentBroadCast implements PendingIntentNotification {
13 | private final Bundle mBundle;
14 | private final int mIdentifier;
15 |
16 | public ClickPendingIntentBroadCast(Bundle bundle, int identifier) {
17 | this.mBundle = bundle;
18 | this.mIdentifier = identifier;
19 | }
20 |
21 | @Override
22 | public PendingIntent onSettingPendingIntent() {
23 | Intent clickIntentBroadcast = new Intent(BroadcastActions.ACTION_CLICK_INTENT);
24 | clickIntentBroadcast.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
25 | clickIntentBroadcast.setPackage(ZadakNotification.mSingleton.mContext.getPackageName());
26 | if (mBundle != null) {
27 | clickIntentBroadcast.putExtras(mBundle);
28 | }
29 |
30 | return PendingIntent.getBroadcast(ZadakNotification.mSingleton.mContext, mIdentifier, clickIntentBroadcast,
31 | PendingIntent.FLAG_UPDATE_CURRENT);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/pendingintent/DismissPendingIntentBroadCast.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.pendingintent;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 |
7 | import ir.zadak.zadaknotify.constants.BroadcastActions;
8 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
9 | import ir.zadak.zadaknotify.notification.ZadakNotification;
10 |
11 |
12 | public class DismissPendingIntentBroadCast implements PendingIntentNotification {
13 | private final Bundle mBundle;
14 | private final int mIdentifier;
15 |
16 | public DismissPendingIntentBroadCast(Bundle bundle, int identifier) {
17 | this.mBundle = bundle;
18 | this.mIdentifier = identifier;
19 | }
20 |
21 | @Override
22 | public PendingIntent onSettingPendingIntent() {
23 | Intent clickIntentBroadcast = new Intent(BroadcastActions.ACTION_DISMISS_INTENT);
24 | clickIntentBroadcast.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
25 | clickIntentBroadcast.setPackage(ZadakNotification.mSingleton.mContext.getPackageName());
26 | if (mBundle != null) {
27 | clickIntentBroadcast.putExtras(mBundle);
28 | }
29 |
30 | return PendingIntent.getBroadcast(ZadakNotification.mSingleton.mContext, mIdentifier, clickIntentBroadcast,
31 | PendingIntent.FLAG_UPDATE_CURRENT);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/pendingintent/ClickPendingIntentActivity.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.pendingintent;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 |
7 | import ir.zadak.zadaknotify.constants.BroadcastActions;
8 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
9 | import ir.zadak.zadaknotify.notification.ZadakNotification;
10 |
11 |
12 | public class ClickPendingIntentActivity implements PendingIntentNotification {
13 | private final Class> mActivity;
14 | private final Bundle mBundle;
15 | private final int mIdentifier;
16 |
17 | public ClickPendingIntentActivity(Class> activity, Bundle bundle, int identifier) {
18 | this.mActivity = activity;
19 | this.mBundle = bundle;
20 | this.mIdentifier = identifier;
21 | }
22 |
23 | @Override
24 | public PendingIntent onSettingPendingIntent() {
25 | Intent clickIntentActivity = new Intent(ZadakNotification.mSingleton.mContext, mActivity);
26 | clickIntentActivity.setAction(BroadcastActions.ACTION_CLICK_INTENT);
27 | clickIntentActivity.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
28 | clickIntentActivity.setPackage(ZadakNotification.mSingleton.mContext.getPackageName());
29 |
30 | if (mBundle != null) {
31 | clickIntentActivity.putExtras(mBundle);
32 | }
33 | return PendingIntent.getActivity(ZadakNotification.mSingleton.mContext, mIdentifier, clickIntentActivity,
34 | PendingIntent.FLAG_UPDATE_CURRENT);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/pendingintent/DismissPendingIntentActivity.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.pendingintent;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 |
7 | import ir.zadak.zadaknotify.constants.BroadcastActions;
8 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
9 | import ir.zadak.zadaknotify.notification.ZadakNotification;
10 |
11 |
12 | public class DismissPendingIntentActivity implements PendingIntentNotification {
13 | private final Class> mActivity;
14 | private final Bundle mBundle;
15 | private final int mIdentifier;
16 |
17 | public DismissPendingIntentActivity(Class> activity, Bundle bundle, int identifier) {
18 | this.mActivity = activity;
19 | this.mBundle = bundle;
20 | this.mIdentifier = identifier;
21 | }
22 |
23 | @Override
24 | public PendingIntent onSettingPendingIntent() {
25 | Intent dismissIntentActivity = new Intent(ZadakNotification.mSingleton.mContext, mActivity);
26 | dismissIntentActivity.setAction(BroadcastActions.ACTION_DISMISS_INTENT);
27 | dismissIntentActivity.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
28 | dismissIntentActivity.setPackage(ZadakNotification.mSingleton.mContext.getPackageName());
29 | if (mBundle != null) {
30 | dismissIntentActivity.putExtras(mBundle);
31 | }
32 |
33 | return PendingIntent.getActivity(ZadakNotification.mSingleton.mContext, mIdentifier, dismissIntentActivity,
34 | PendingIntent.FLAG_UPDATE_CURRENT);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Builder.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.app.Notification;
4 | import android.support.v4.app.NotificationCompat;
5 | import android.support.v4.app.NotificationManagerCompat;
6 | import android.util.Log;
7 | import android.widget.RemoteViews;
8 |
9 | public abstract class Builder {
10 | private static final String TAG = Builder.class.getSimpleName();
11 | protected String tag;
12 | protected Notification notification;
13 | protected NotificationCompat.Builder builder;
14 | protected int notificationId;
15 |
16 | public Builder(NotificationCompat.Builder builder, int identifier, String tag) {
17 | this.builder = builder;
18 | this.notificationId = identifier;
19 | this.tag = tag;
20 | }
21 |
22 | public void build() {
23 | notification = builder.build();
24 | }
25 |
26 | public void setBigContentView(RemoteViews views) {
27 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
28 | notification.bigContentView = views;
29 | return;
30 | }
31 | Log.w(TAG, "Version does not support big content view");
32 | }
33 |
34 | protected Notification notificationNotify() {
35 | if (tag != null) {
36 | return notificationNotify(tag, notificationId);
37 | }
38 | return notificationNotify(notificationId);
39 | }
40 |
41 | protected Notification notificationNotify(int identifier) {
42 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ZadakNotification.mSingleton.mContext);
43 | notificationManager.notify(identifier, notification);
44 | return notification;
45 | }
46 |
47 | protected Notification notificationNotify(String tag, int identifier) {
48 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ZadakNotification.mSingleton.mContext);
49 | notificationManager.notify(tag, identifier, notification);
50 | return notification;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/ZadakNotification.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.app.NotificationManager;
4 | import android.content.Context;
5 |
6 | public class ZadakNotification {
7 | private static final String TAG = ZadakNotification.class.getSimpleName();
8 | public static ZadakNotification mSingleton = null;
9 | public final Context mContext;
10 | public boolean shutdown;
11 |
12 | public ZadakNotification(Context context) {
13 | this.mContext = context;
14 | }
15 |
16 | public static ZadakNotification with(Context context) {
17 | if (mSingleton == null) {
18 | synchronized (ZadakNotification.class) {
19 | if (mSingleton == null) {
20 | mSingleton = new Contractor(context).build();
21 | }
22 | }
23 | }
24 | return mSingleton;
25 | }
26 |
27 | public Load load() {
28 | return new Load();
29 | }
30 |
31 | public void cancel(int identifier) {
32 | NotificationManager notifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
33 | notifyManager.cancel(identifier);
34 | }
35 |
36 | public void cancel(String tag, int identifier) {
37 | NotificationManager notifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
38 | notifyManager.cancel(tag, identifier);
39 | }
40 |
41 | public void shutdown() {
42 | if (this == mSingleton) {
43 | throw new UnsupportedOperationException("Default singleton instance cannot be shutdown.");
44 | }
45 | if (shutdown) {
46 | return;
47 | }
48 | shutdown = true;
49 | }
50 |
51 | private static class Contractor {
52 | private final Context mContext;
53 |
54 | public Contractor(Context context) {
55 | if (context == null) {
56 | throw new IllegalArgumentException("Context must not be null.");
57 | }
58 | this.mContext = context.getApplicationContext();
59 | }
60 |
61 | public ZadakNotification build() {
62 | return new ZadakNotification(mContext);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/res/layout/notification_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
33 |
34 |
45 |
46 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/model/NotificationBean.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.model;
2 |
3 | import android.app.PendingIntent;
4 | import android.graphics.Bitmap;
5 | import android.net.Uri;
6 |
7 | public class NotificationBean {
8 | private int identifier;
9 | private String title;
10 | private String message;
11 | private String bigTextStyle;
12 | private String ticker;
13 | private int background;
14 | private int smallIcon;
15 | private int colorLight;
16 | private int ledOnMs;
17 | private int ledOffMs;
18 | private long when;
19 | private long[] vibratorTime;
20 | private boolean autoCancel;
21 | private Bitmap largeIcon;
22 | private Uri sound;
23 | private PendingIntent clickPendingIntent;
24 | private PendingIntent dismissPendingIntent;
25 |
26 | public NotificationBean() {
27 | super();
28 | }
29 |
30 | public int getIdentifier() {
31 | return identifier;
32 | }
33 |
34 | public void setIdentifier(int identifier) {
35 | this.identifier = identifier;
36 | }
37 |
38 | public String getTitle() {
39 | return title;
40 | }
41 |
42 | public void setTitle(String title) {
43 | this.title = title;
44 | }
45 |
46 | public String getMessage() {
47 | return message;
48 | }
49 |
50 | public void setMessage(String message) {
51 | this.message = message;
52 | }
53 |
54 | public String getBigTextStyle() {
55 | return bigTextStyle;
56 | }
57 |
58 | public void setBigTextStyle(String bigTextStyle) {
59 | this.bigTextStyle = bigTextStyle;
60 | }
61 |
62 | public String getTicker() {
63 | return ticker;
64 | }
65 |
66 | public void setTicker(String ticker) {
67 | this.ticker = ticker;
68 | }
69 |
70 | public int getBackground() {
71 | return background;
72 | }
73 |
74 | public void setBackground(int background) {
75 | this.background = background;
76 | }
77 |
78 | public int getSmallIcon() {
79 | return smallIcon;
80 | }
81 |
82 | public void setSmallIcon(int smallIcon) {
83 | this.smallIcon = smallIcon;
84 | }
85 |
86 | public int getColorLight() {
87 | return colorLight;
88 | }
89 |
90 | public void setColorLight(int colorLight) {
91 | this.colorLight = colorLight;
92 | }
93 |
94 | public int getLedOnMs() {
95 | return ledOnMs;
96 | }
97 |
98 | public void setLedOnMs(int ledOnMs) {
99 | this.ledOnMs = ledOnMs;
100 | }
101 |
102 | public int getLedOffMs() {
103 | return ledOffMs;
104 | }
105 |
106 | public void setLedOffMs(int ledOffMs) {
107 | this.ledOffMs = ledOffMs;
108 | }
109 |
110 | public long getWhen() {
111 | return when;
112 | }
113 |
114 | public void setWhen(long when) {
115 | this.when = when;
116 | }
117 |
118 | public long[] getVibratorTime() {
119 | return vibratorTime;
120 | }
121 |
122 | public void setVibratorTime(long[] vibratorTime) {
123 | this.vibratorTime = vibratorTime;
124 | }
125 |
126 | public boolean isAutoCancel() {
127 | return autoCancel;
128 | }
129 |
130 | public void setAutoCancel(boolean autoCancel) {
131 | this.autoCancel = autoCancel;
132 | }
133 |
134 | public Bitmap getLargeIcon() {
135 | return largeIcon;
136 | }
137 |
138 | public void setLargeIcon(Bitmap largeIcon) {
139 | this.largeIcon = largeIcon;
140 | }
141 |
142 | public Uri getSound() {
143 | return sound;
144 | }
145 |
146 | public void setSound(Uri sound) {
147 | this.sound = sound;
148 | }
149 |
150 | public PendingIntent getClickPendingIntent() {
151 | return clickPendingIntent;
152 | }
153 |
154 | public void setClickPendingIntent(PendingIntent clickPendingIntent) {
155 | this.clickPendingIntent = clickPendingIntent;
156 | }
157 |
158 | public PendingIntent getDismissPendingIntent() {
159 | return dismissPendingIntent;
160 | }
161 |
162 | public void setDismissPendingIntent(PendingIntent dismissPendingIntent) {
163 | this.dismissPendingIntent = dismissPendingIntent;
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Custom.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.annotation.TargetApi;
5 | import android.graphics.Bitmap;
6 | import android.os.Looper;
7 | import android.support.annotation.DrawableRes;
8 | import android.support.v4.app.NotificationCompat;
9 | import android.text.Spanned;
10 | import android.widget.RemoteViews;
11 |
12 | import ir.zadak.zadaknotify.R;
13 | import ir.zadak.zadaknotify.interfaces.ImageLoader;
14 | import ir.zadak.zadaknotify.interfaces.OnImageLoadingCompleted;
15 |
16 |
17 | @TargetApi(android.os.Build.VERSION_CODES.JELLY_BEAN)
18 | public class Custom extends Builder implements OnImageLoadingCompleted {
19 | private static final String TAG = Custom.class.getSimpleName();
20 | private RemoteViews mRemoteView;
21 | private String mTitle;
22 | private String mMessage;
23 | private Spanned mMessageSpanned;
24 | private String mUri;
25 | private int mSmallIcon;
26 | private int mBackgroundResId;
27 | private int mPlaceHolderResourceId;
28 | private ImageLoader mImageLoader;
29 |
30 |
31 | public Custom(NotificationCompat.Builder builder, int identifier, String title, String message, Spanned messageSpanned, int smallIcon, String tag) {
32 | super(builder, identifier, tag);
33 | this.mRemoteView = new RemoteViews(ZadakNotification.mSingleton.mContext.getPackageName(), R.layout.notification_custom);
34 | this.mTitle = title;
35 | this.mMessage = message;
36 | this.mMessageSpanned = messageSpanned;
37 | this.mSmallIcon = smallIcon;
38 | this.mPlaceHolderResourceId = R.drawable.ic_launcher;
39 | this.init();
40 | }
41 |
42 | private void init() {
43 | this.setTitle();
44 | this.setMessage();
45 | this.setSmallIcon();
46 | }
47 |
48 | private void setTitle() {
49 | mRemoteView.setTextViewText(R.id.notification_text_title, mTitle);
50 | }
51 |
52 | private void setMessage() {
53 | if (mMessageSpanned != null) {
54 | mRemoteView.setTextViewText(R.id.notification_text_message, mMessageSpanned);
55 | } else {
56 | mRemoteView.setTextViewText(R.id.notification_text_message, mMessage);
57 | }
58 | }
59 |
60 | private void setSmallIcon() {
61 | if (mSmallIcon <= 0) {
62 | mRemoteView.setImageViewResource(R.id.notification_img_icon, R.drawable.ic_launcher);
63 | }
64 | mRemoteView.setImageViewResource(R.id.notification_img_icon, mSmallIcon);
65 | }
66 |
67 | @SuppressLint("ResourceType")
68 | public Custom background(@DrawableRes int resource) {
69 | if (resource <= 0) {
70 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
71 | }
72 |
73 | if (mUri != null) {
74 | throw new IllegalStateException("Background Already Set!");
75 | }
76 |
77 | this.mBackgroundResId = resource;
78 | return this;
79 | }
80 |
81 | @SuppressLint("ResourceType")
82 | public Custom setPlaceholder(@DrawableRes int resource) {
83 | if (resource <= 0) {
84 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
85 | }
86 |
87 | this.mPlaceHolderResourceId = resource;
88 | return this;
89 | }
90 |
91 | public Custom setImageLoader(ImageLoader imageLoader) {
92 | this.mImageLoader = imageLoader;
93 | return this;
94 | }
95 |
96 | public Custom background(String uri) {
97 | if (mBackgroundResId > 0) {
98 | throw new IllegalStateException("Background Already Set!");
99 | }
100 |
101 | if (mUri != null) {
102 | throw new IllegalStateException("Background Already Set!");
103 | }
104 |
105 | if (uri == null) {
106 | throw new IllegalArgumentException("Path Must Not Be Null!");
107 | }
108 | if (uri.trim().length() == 0) {
109 | throw new IllegalArgumentException("Path Must Not Be Empty!");
110 | }
111 |
112 | if (mImageLoader == null) {
113 | throw new IllegalStateException("You have to set an ImageLoader!");
114 | }
115 |
116 | this.mUri = uri;
117 | return this;
118 | }
119 |
120 | @Override
121 | public void build() {
122 | if (!(Looper.getMainLooper().getThread() == Thread.currentThread())) {
123 | throw new IllegalStateException("Method call should happen from the main thread.");
124 | }
125 |
126 | super.build();
127 | setBigContentView(mRemoteView);
128 | loadImageBackground();
129 | super.notificationNotify();
130 | }
131 |
132 | private void loadImageBackground() {
133 |
134 | mRemoteView.setImageViewResource(R.id.notification_img_background, mPlaceHolderResourceId);
135 | if (mUri != null) {
136 | mImageLoader.load(mUri, this);
137 | } else {
138 | mImageLoader.load(mBackgroundResId, this);
139 | }
140 | }
141 |
142 | @Override
143 | public void imageLoadingCompleted(Bitmap bitmap) {
144 | if (bitmap == null) {
145 | throw new IllegalArgumentException("bitmap cannot be null");
146 | }
147 | mRemoteView.setImageViewBitmap(R.id.notification_img_background, bitmap);
148 | super.notificationNotify();
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZadakNotification
2 | # Download
3 | # Step 1:
4 | Add it in your root build.gradle at the end of repositories:
5 | ``` groovy
6 | allprojects {
7 | repositories {
8 | maven { url 'https://jitpack.io' }
9 | }
10 | }
11 | ```
12 | # Step 2:
13 | Add the dependency:
14 | ```groovy
15 | implementation 'com.github.mehrdadsafari:ZadakNotification:0.0.2'
16 | ```
17 |
18 | # Introduction
19 |
20 | 
21 |
22 | You're probably tired of writing code to display notifications in your applications, the library abstracts all the notifications construction process for you in a single line of code. this library support Android Wear.
23 |
24 | ```java
25 | ZadakNotification.with(context)
26 | .load()
27 | .notificationChannelId(CHANNEL_ID)
28 | .identifier(identifier)
29 | .title(title)
30 | .message(message)
31 | .bigTextStyle(bigtext)
32 | .smallIcon(smallIcon)
33 | .largeIcon(largeIcon)
34 | .flags(Notification.DEFAULT_ALL)
35 | .button(icon, title, pendingIntent)
36 | .click(cctivity, bundle)
37 | .dismiss(activity, bundle)
38 | .color(color)
39 | .ticker(ticker)
40 | .when(when)
41 | .vibrate(vibrate)
42 | .lights(color, ledOnMs, ledOfMs)
43 | .sound(sound)
44 | .autoCancel(autoCancel)
45 | .simple()
46 | .build();
47 | ```
48 | # Simple Notification
49 |
50 | Simple notification with just text and message.
51 |
52 | ```java
53 | ZadakNotification.with(context)
54 | .load()
55 | .notificationChannelId(CHANNEL_ID)
56 | .title(title)
57 | .message(message)
58 | .bigTextStyle(bigtext)
59 | .smallIcon(R.drawable.ic_launcher)
60 | .largeIcon(R.drawable.ic_launcher)
61 | .flags(Notification.DEFAULT_ALL)
62 | .simple()
63 | .build();
64 | ```
65 |
66 | # Progress Notification
67 |
68 | Simple notification with progress.
69 |
70 | ```java
71 | ZadakNotification.with(context)
72 | .load()
73 | .notificationChannelId(CHANNEL_ID)
74 | .identifier(identifier)
75 | .smallIcon(R.drawable.ic_launcher)
76 | .progress()
77 | .value(progress,max, indeterminate)
78 | .build();
79 | ```
80 |
81 | ```java
82 | ZadakNotification.with(context)
83 | .load()
84 | .notificationChannelId(CHANNEL_ID)
85 | .identifier(identifier)
86 | .smallIcon(R.drawable.ic_launcher)
87 | .progress()
88 | .update(identifier,progress,max, indeterminate)
89 | .build();
90 | ```
91 |
92 | # Custom Notification
93 |
94 | We have changed the way the library handles the download images for custom notifications. Previously disrespectfully because of the Picasso library. But many users were asking for the option of being able to choose how to download the image.
95 | So we serve the requests and modify the library to allow the download of image management as an example:
96 |
97 | ```java
98 | ZadakNotification.with(context)
99 | .load()
100 | .notificationChannelId(CHANNEL_ID)
101 | .title(title)
102 | .message(message)
103 | .bigTextStyle(bigtext)
104 | .smallIcon(R.drawable.ic_launcher)
105 | .largeIcon(R.drawable.ic_launcher)
106 | .flags(Notification.DEFAULT_ALL)
107 | .color(android.R.color.background_dark)
108 | .custom()
109 | .background(url)
110 | .setImageLoader(Callback)
111 | .setPlaceholder(R.drawable.ic_placeholder)
112 | .build();
113 | ```
114 |
115 |
116 | # Wear Notification
117 |
118 | ```java
119 | ZadakNotification.with(mContext).load()
120 | .notificationChannelId(CHANNEL_ID)
121 | .smallIcon(R.drawable.ic_launcher)
122 | .autoCancel(true)
123 | .largeIcon(R.drawable.ic_launcher)
124 | .title(title)
125 | .message(message)
126 | .bigTextStyle(bigtext)
127 | .flags(Notification.DEFAULT_ALL)
128 | .wear()
129 | .background(Bitmap)
130 | .setRemoteInput(icon, title, pendingIntent, remoteInput)
131 | .setPages(List listNotification)
132 | .setHideIcon(Boolean)
133 | .build();
134 | ```
135 |
136 | Now just the client implement the ImageLoader interface and implement a way to manage the download of the image. Below we use the Picasso:
137 |
138 | ```java
139 | @Override
140 | public void load(String uri, final OnImageLoadingCompleted onCompleted) {
141 | viewTarget = getViewTarget(onCompleted);
142 | Picasso.with(this).load(uri).into(viewTarget);
143 | }
144 |
145 | private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
146 | return new Target() {
147 | @Override
148 | public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
149 | onCompleted.imageLoadingCompleted(bitmap);
150 | }
151 |
152 | @Override
153 | public void onBitmapFailed(Drawable errorDrawable) {
154 | }
155 |
156 | @Override
157 | public void onPrepareLoad(Drawable placeHolderDrawable) {
158 | }
159 | };
160 | }
161 | ```
162 | ZadakNotification supports placeholders if download the image in the background is not successful. The library already have a default placeholder size 622x384.
163 |
164 | # Important note
165 | For disable the swipe delete notification use
166 | ```
167 | .setOngoing(true)
168 | ```
169 | Cancel Notification
170 | ```
171 | ZadakNotification.with(mContext).cancel(identifier);
172 | ```
173 | # ProGuard
174 |
175 | If you use the Picasso to manage the download of the image, add the line below to your proguard file:
176 |
177 | ```
178 | -dontwarn com.squareup.okhttp.**
179 | ```
180 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_activity.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
13 |
14 |
22 |
23 |
27 |
28 |
36 |
37 |
47 |
48 |
49 |
53 |
54 |
61 |
62 |
71 |
72 |
73 |
74 |
75 |
76 |
80 |
81 |
82 |
89 |
90 |
99 |
100 |
101 |
102 |
107 |
108 |
115 |
116 |
125 |
126 |
127 |
128 |
133 |
134 |
142 |
143 |
144 |
148 |
149 |
156 |
157 |
166 |
167 |
168 |
173 |
174 |
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Wear.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Notification;
5 | import android.app.PendingIntent;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.support.annotation.DrawableRes;
9 | import android.support.annotation.StringRes;
10 | import android.support.v4.app.NotificationCompat;
11 | import android.support.v4.app.RemoteInput;
12 |
13 | import java.util.List;
14 |
15 | import ir.zadak.zadaknotify.R;
16 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
17 |
18 | public class Wear extends Builder {
19 | private NotificationCompat.WearableExtender wearableExtender;
20 | private RemoteInput remoteInput;
21 |
22 | public Wear(NotificationCompat.Builder builder, int identifier, String tag) {
23 | super(builder, identifier, tag);
24 | this.wearableExtender = new NotificationCompat.WearableExtender();
25 | }
26 |
27 | public Wear hideIcon(boolean hideIcon) {
28 | wearableExtender.setHintHideIcon(hideIcon);
29 | return this;
30 | }
31 |
32 | public Wear contentIcon(@DrawableRes int contentIcon) {
33 | wearableExtender.setContentIcon(contentIcon);
34 | return this;
35 | }
36 |
37 | public Wear addPages(Notification notification) {
38 | if (notification == null) {
39 | throw new IllegalArgumentException("Notification Must Not Be Null.");
40 | }
41 |
42 | wearableExtender.addPage(notification);
43 | return this;
44 | }
45 |
46 | public Wear addPages(List notificationList) {
47 | if (notificationList == null || notificationList.isEmpty()) {
48 | throw new IllegalArgumentException("List Notitifcation Must Not Be Null And Empty!");
49 | }
50 |
51 | wearableExtender.addPages(notificationList);
52 | return this;
53 | }
54 |
55 | @SuppressLint("ResourceType")
56 | public Wear button(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
57 | if (icon < 0) {
58 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
59 | }
60 |
61 | if (title == null) {
62 | throw new IllegalStateException("Title Must Not Be Null!");
63 | }
64 | if (pendingIntent == null) {
65 | throw new IllegalArgumentException("PendingIntent Must Not Be Null.");
66 | }
67 |
68 | this.wearableExtender.addAction(new NotificationCompat.Action(icon, title, pendingIntent));
69 | return this;
70 | }
71 |
72 |
73 | public Wear remoteInput(@DrawableRes int icon, @StringRes int title, PendingIntentNotification pendingIntentNotification, RemoteInput remoteInput) {
74 | remoteInput(icon, ZadakNotification.mSingleton.mContext.getString(title), pendingIntentNotification.onSettingPendingIntent(), remoteInput);
75 | return this;
76 | }
77 |
78 | public Wear remoteInput(@DrawableRes int icon, String title, PendingIntentNotification pendingIntentNotification, RemoteInput remoteInput) {
79 | remoteInput(icon, title, pendingIntentNotification.onSettingPendingIntent(), remoteInput);
80 | return this;
81 | }
82 |
83 | public Wear remoteInput(@DrawableRes int icon, @StringRes int title, PendingIntent pendingIntent, RemoteInput remoteInput) {
84 | remoteInput(icon, ZadakNotification.mSingleton.mContext.getString(title), pendingIntent, remoteInput);
85 | return this;
86 | }
87 |
88 | @SuppressLint("ResourceType")
89 | public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent, RemoteInput remoteInput) {
90 | if (icon <= 0) {
91 | throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
92 | }
93 |
94 | if (title == null) {
95 | throw new IllegalArgumentException("Title Must Not Be Null!");
96 | }
97 |
98 | if (pendingIntent == null) {
99 | throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
100 | }
101 |
102 | if (remoteInput == null) {
103 | throw new IllegalArgumentException("RemoteInput Must Not Be Null!");
104 | }
105 |
106 | this.remoteInput = remoteInput;
107 | wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
108 | title, pendingIntent)
109 | .addRemoteInput(remoteInput)
110 | .build());
111 | return this;
112 | }
113 |
114 | @SuppressLint("ResourceType")
115 | public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
116 | if (icon <= 0) {
117 | throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
118 | }
119 |
120 | if (title == null) {
121 | throw new IllegalArgumentException("Title Must Not Be Null!");
122 | }
123 |
124 | if (pendingIntent == null) {
125 | throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
126 | }
127 |
128 | this.remoteInput = new RemoteInput.Builder(ZadakNotification.mSingleton.mContext.getString(R.string.key_voice_reply))
129 | .setLabel(ZadakNotification.mSingleton.mContext.getString(R.string.label_voice_reply))
130 | .setChoices(ZadakNotification.mSingleton.mContext.getResources().getStringArray(R.array.reply_choices))
131 | .build();
132 | wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
133 | title, pendingIntent)
134 | .addRemoteInput(remoteInput)
135 | .build());
136 | return this;
137 | }
138 |
139 | public Wear remoteInput(@DrawableRes int icon, @StringRes int title, PendingIntent pendingIntent, String replyLabel, String[] replyChoices) {
140 | return remoteInput(icon, ZadakNotification.mSingleton.mContext.getString(title), pendingIntent, replyLabel, replyChoices);
141 | }
142 |
143 | @SuppressLint("ResourceType")
144 | public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent, String replyLabel, String[] replyChoices) {
145 | if (icon <= 0) {
146 | throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
147 | }
148 |
149 | if (title == null) {
150 | throw new IllegalArgumentException("Title Must Not Be Null!");
151 | }
152 |
153 | if (replyChoices == null) {
154 | throw new IllegalArgumentException("Reply Choices Must Not Be Null!");
155 | }
156 |
157 | if (pendingIntent == null) {
158 | throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
159 | }
160 | if (replyLabel == null) {
161 | throw new IllegalArgumentException("Reply Label Must Not Be Null!");
162 | }
163 |
164 | this.remoteInput = new RemoteInput.Builder(ZadakNotification.mSingleton.mContext.getString(R.string.key_voice_reply))
165 | .setLabel(replyLabel)
166 | .setChoices(replyChoices)
167 | .build();
168 | wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
169 | title, pendingIntent)
170 | .addRemoteInput(remoteInput)
171 | .build());
172 | return this;
173 | }
174 |
175 | public Wear background(Bitmap bitmap) {
176 | if (bitmap == null) {
177 | throw new IllegalArgumentException("Bitmap Must Not Be Null.");
178 | }
179 |
180 | this.wearableExtender.setBackground(bitmap);
181 | return this;
182 | }
183 |
184 | @SuppressLint("ResourceType")
185 | public Wear background(@DrawableRes int background) {
186 | if (background <= 0) {
187 | throw new IllegalArgumentException("Resource ID Background Should Not Be Less Than Or Equal To Zero!");
188 | }
189 |
190 | Bitmap bitmap = BitmapFactory.decodeResource(ZadakNotification.mSingleton.mContext.getResources(), background);
191 | this.wearableExtender.setBackground(bitmap);
192 | return this;
193 | }
194 |
195 | public Wear startScrollBottom(boolean startScrollBottom) {
196 | this.wearableExtender.setStartScrollBottom(startScrollBottom);
197 | return this;
198 | }
199 |
200 | @Override
201 | public void build() {
202 | builder.extend(wearableExtender);
203 | super.build();
204 | super.notificationNotify();
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/zadak/notification/Sample.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.notification;
2 |
3 | import android.app.Notification;
4 | import android.app.NotificationChannel;
5 | import android.app.NotificationManager;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.text.TextUtils;
13 | import android.view.View;
14 | import android.widget.AdapterView;
15 | import android.widget.ArrayAdapter;
16 | import android.widget.Button;
17 | import android.widget.EditText;
18 | import android.widget.RelativeLayout;
19 | import android.widget.Spinner;
20 | import android.widget.Toast;
21 | import com.squareup.picasso.Picasso;
22 | import com.squareup.picasso.Target;
23 |
24 | import ir.zadak.zadaknotify.interfaces.ImageLoader;
25 | import ir.zadak.zadaknotify.interfaces.OnImageLoadingCompleted;
26 | import ir.zadak.zadaknotify.notification.Load;
27 | import ir.zadak.zadaknotify.notification.ZadakNotification;
28 |
29 |
30 | public class Sample extends AppCompatActivity implements ImageLoader {
31 | private static final String CHANNEL_ID = "NOTIFICATION_CHANNEL_ID";
32 | private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
33 | return new Target() {
34 |
35 | @Override
36 | public void onBitmapFailed(final Exception e, final Drawable errorDrawable) {
37 |
38 | }
39 |
40 | @Override
41 | public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
42 | onCompleted.imageLoadingCompleted(bitmap);
43 | }
44 |
45 | @Override
46 | public void onPrepareLoad(Drawable placeHolderDrawable) {
47 |
48 | }
49 | };
50 | }
51 |
52 | private Button mBtnNotifySimple, mBtnNotifyCustom;
53 | private RelativeLayout mContentBigText;
54 | private Context mContext;
55 | private EditText mEdtTitle, mEdtMessage, mEdtBigText, mEdtUrl;
56 | private int mPosSelected = 0;
57 | private Spinner mSpnType;
58 | // Keep a strong reference to keep it from being garbage collected inside into method
59 | private Target viewTarget;
60 |
61 | @Override
62 | public void load(String uri, final OnImageLoadingCompleted onCompleted) {
63 | viewTarget = getViewTarget(onCompleted);
64 | Picasso.get().load(uri).into(viewTarget);
65 | }
66 |
67 | @Override
68 | public void load(int imageResId, OnImageLoadingCompleted onCompleted) {
69 | viewTarget = getViewTarget(onCompleted);
70 | Picasso.get().load(imageResId).into(viewTarget);
71 | }
72 |
73 | @Override
74 | protected void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | mContext = this;
77 | setContentView(R.layout.sample_activity);
78 |
79 | createNotificationChannel();
80 | loadInfoComponents();
81 | loadListeners();
82 | }
83 |
84 | private void createNotificationChannel() {
85 | // Create the NotificationChannel, but only on API 26+ because
86 | // the NotificationChannel class is new and not in the support library
87 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
88 | CharSequence name = "My app notification channel";
89 | String description = "Description for this channel";
90 | int importance = NotificationManager.IMPORTANCE_DEFAULT;
91 | NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
92 | channel.setDescription(description);
93 | // Register the channel with the system; you can't change the importance
94 | // or other notification behaviors after this
95 | NotificationManager notificationManager = getSystemService(NotificationManager.class);
96 | notificationManager.createNotificationChannel(channel);
97 | }
98 | }
99 |
100 | private void loadInfoComponents() {
101 | this.mEdtMessage = findViewById(R.id.edt_message);
102 | this.mEdtTitle = findViewById(R.id.edt_title);
103 | this.mEdtBigText = findViewById(R.id.edt_bigtext);
104 | this.mEdtUrl = findViewById(R.id.edt_url);
105 | this.mBtnNotifySimple = findViewById(R.id.btn_notify_simple);
106 | this.mBtnNotifyCustom = findViewById(R.id.btn_notify_custom);
107 | this.mSpnType = findViewById(R.id.spn_notification_type);
108 | ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
109 | R.array.notification_types, android.R.layout.simple_spinner_item);
110 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
111 | this.mSpnType.setAdapter(adapter);
112 |
113 | this.mContentBigText = findViewById(R.id.content_bigtext);
114 | }
115 |
116 | private void loadListeners() {
117 | mSpnType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
118 | @Override
119 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
120 | mPosSelected = position;
121 | switch (position) {
122 | case 0:
123 | mContentBigText.setVisibility(View.GONE);
124 | break;
125 | case 1:
126 | mContentBigText.setVisibility(View.VISIBLE);
127 | break;
128 | case 2:
129 | mContentBigText.setVisibility(View.GONE);
130 | break;
131 | }
132 | }
133 |
134 | @Override
135 | public void onNothingSelected(AdapterView> parent) {
136 |
137 | }
138 | });
139 | mBtnNotifySimple.setOnClickListener(new View.OnClickListener() {
140 | @Override
141 | public void onClick(View v) {
142 | String title = mEdtTitle.getText().toString();
143 | String message = mEdtMessage.getText().toString();
144 | String bigtext = mEdtBigText.getText().toString();
145 | if (title.length() > 0 && message.length() > 0) {
146 | Load mLoad = ZadakNotification.with(mContext).load()
147 | .notificationChannelId(CHANNEL_ID)
148 | .smallIcon(R.drawable.ic_launcher)
149 | .autoCancel(true)
150 | .largeIcon(R.drawable.ic_launcher)
151 | .title(title)
152 | .message(message)
153 | .flags(Notification.DEFAULT_ALL);
154 |
155 | switch (mPosSelected) {
156 | case 0:
157 | mLoad.simple()
158 | .build();
159 | break;
160 | case 1:
161 | if (bigtext.length() > 0) {
162 | mLoad.bigTextStyle(bigtext, message)
163 | .simple()
164 | .build();
165 | } else {
166 | notifyEmptyFields();
167 | }
168 | break;
169 | case 2:
170 | mLoad.inboxStyle(getResources().
171 | getStringArray(R.array.notification_inbox_lines),
172 | title,
173 | getResources().getString(R.string.text_summary))
174 | .simple()
175 | .build();
176 | break;
177 | }
178 | } else {
179 | notifyEmptyFields();
180 | }
181 | }
182 | });
183 |
184 | mBtnNotifyCustom.setOnClickListener(new View.OnClickListener()
185 |
186 | {
187 | @Override
188 | public void onClick(View v) {
189 | String title = mEdtTitle.getText().toString();
190 | String message = mEdtMessage.getText().toString();
191 | String bigtext = mEdtBigText.getText().toString();
192 | String url = mEdtUrl.getText().toString();
193 |
194 |
195 | if (TextUtils.isEmpty(title) || TextUtils.isEmpty(message) || TextUtils.isEmpty(bigtext) || TextUtils
196 | .isEmpty(url)) {
197 | mSpnType.setSelection(1);
198 | notifyEmptyFields();
199 | return;
200 | }
201 |
202 | ZadakNotification.with(mContext).load()
203 | .notificationChannelId(CHANNEL_ID)
204 | .title(title)
205 | .message(message)
206 | .bigTextStyle(bigtext)
207 | .smallIcon(R.drawable.ic_launcher)
208 | .largeIcon(R.drawable.ic_launcher)
209 | .color(android.R.color.background_dark)
210 | .custom()
211 | .setImageLoader(Sample.this)
212 | .background(url)
213 | .setPlaceholder(R.drawable.ic_placeholder)
214 | .build();
215 | }
216 | });
217 | }
218 |
219 | private void notifyEmptyFields() {
220 | Toast.makeText(getApplicationContext(),
221 | R.string.text_empty_fields,
222 | Toast.LENGTH_SHORT).show();
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 | }
236 | }
--------------------------------------------------------------------------------
/zadaknotify/src/main/java/ir/zadak/zadaknotify/notification/Load.java:
--------------------------------------------------------------------------------
1 | package ir.zadak.zadaknotify.notification;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.PendingIntent;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.net.Uri;
10 | import android.os.Build;
11 | import android.os.Bundle;
12 | import android.support.annotation.ColorRes;
13 | import android.support.annotation.DrawableRes;
14 | import android.support.annotation.NonNull;
15 | import android.support.annotation.StringRes;
16 | import android.support.v4.app.NotificationCompat;
17 | import android.text.Spanned;
18 |
19 | import ir.zadak.zadaknotify.interfaces.PendingIntentNotification;
20 | import ir.zadak.zadaknotify.pendingintent.ClickPendingIntentActivity;
21 | import ir.zadak.zadaknotify.pendingintent.ClickPendingIntentBroadCast;
22 | import ir.zadak.zadaknotify.pendingintent.DismissPendingIntentActivity;
23 | import ir.zadak.zadaknotify.pendingintent.DismissPendingIntentBroadCast;
24 |
25 |
26 | public class Load {
27 |
28 | private NotificationCompat.Builder builder;
29 |
30 | private String message;
31 | private Spanned messageSpanned;
32 | private String notificationChannelId;
33 | private int notificationId;
34 | private int smallIcon;
35 | private String tag;
36 | private String title;
37 |
38 | public Load() {
39 | builder = new NotificationCompat.Builder(ZadakNotification.mSingleton.mContext);
40 | builder.setContentIntent(PendingIntent.getBroadcast(ZadakNotification.mSingleton.mContext, 0, new Intent(),
41 | PendingIntent.FLAG_UPDATE_CURRENT));
42 | }
43 |
44 | public Load addPerson(@NonNull String uri) {
45 | if (uri.length() == 0) {
46 | throw new IllegalArgumentException("URI Must Not Be Empty!");
47 | }
48 |
49 | this.builder.addPerson(uri);
50 | return this;
51 | }
52 |
53 | public Load autoCancel(boolean autoCancel) {
54 | this.builder.setAutoCancel(autoCancel);
55 | return this;
56 | }
57 |
58 | @SuppressLint("ResourceType")
59 | public Load bigTextStyle(@StringRes int bigTextStyle) {
60 | if (bigTextStyle <= 0) {
61 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
62 | }
63 |
64 | return bigTextStyle(ZadakNotification.mSingleton.mContext.getResources().getString(
65 |
66 | bigTextStyle), null);
67 | }
68 |
69 | @SuppressLint("ResourceType")
70 | public Load bigTextStyle(@StringRes int bigTextStyle, @StringRes int summaryText) {
71 | if (bigTextStyle <= 0) {
72 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
73 | }
74 |
75 | return bigTextStyle(ZadakNotification.mSingleton.mContext.getResources().getString(
76 | bigTextStyle), ZadakNotification.mSingleton.mContext.getResources().getString(
77 | summaryText));
78 | }
79 |
80 | public Load bigTextStyle(@NonNull String bigTextStyle) {
81 | if (bigTextStyle.trim().length() == 0) {
82 | throw new IllegalArgumentException("Big Text Style Must Not Be Empty!");
83 | }
84 |
85 | return bigTextStyle(bigTextStyle, null);
86 |
87 |
88 | }
89 |
90 | public Load bigTextStyle(@NonNull String bigTextStyle, String summaryText) {
91 | if (bigTextStyle.trim().length() == 0) {
92 | throw new IllegalArgumentException("Big Text Style Must Not Be Empty!");
93 | }
94 |
95 | NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
96 | bigStyle.bigText(bigTextStyle);
97 | if (summaryText != null) {
98 | bigStyle.setSummaryText(summaryText);
99 | }
100 |
101 |
102 | this.builder.setStyle(bigStyle);
103 | return this;
104 | }
105 |
106 | public Load bigTextStyle(@NonNull Spanned bigTextStyle, String summaryText) {
107 | if (bigTextStyle.length() == 0) {
108 | throw new IllegalArgumentException("Big Text Style Must Not Be Empty!");
109 | }
110 |
111 | NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
112 | bigStyle.bigText(bigTextStyle);
113 | if (summaryText != null) {
114 | bigStyle.setSummaryText(summaryText);
115 | }
116 | this.builder.setStyle(bigStyle);
117 | return this;
118 | }
119 |
120 | public Load button(@DrawableRes int icon, @NonNull String title, @NonNull PendingIntent pendingIntent) {
121 | this.builder.addAction(icon, title, pendingIntent);
122 | return this;
123 | }
124 |
125 | public Load button(@DrawableRes int icon, @NonNull String title,
126 | @NonNull PendingIntentNotification pendingIntentNotification) {
127 | this.builder.addAction(icon, title, pendingIntentNotification.onSettingPendingIntent());
128 |
129 | return this;
130 | }
131 |
132 | public Load button(@NonNull NotificationCompat.Action action) {
133 | this.builder.addAction(action);
134 | return this;
135 | }
136 |
137 | public Load click(@NonNull Class> activity, Bundle bundle) {
138 | this.builder.setContentIntent(new ClickPendingIntentActivity(activity, bundle, notificationId)
139 | .onSettingPendingIntent());
140 | return this;
141 | }
142 |
143 | public Load click(@NonNull Class> activity) {
144 | click(activity, null);
145 | return this;
146 | }
147 |
148 | public Load click(@NonNull Bundle bundle) {
149 | this.builder.setContentIntent(new ClickPendingIntentBroadCast(bundle, notificationId).onSettingPendingIntent());
150 | return this;
151 | }
152 |
153 | public Load click(@NonNull PendingIntentNotification pendingIntentNotification) {
154 | this.builder.setContentIntent(pendingIntentNotification.onSettingPendingIntent());
155 | return this;
156 | }
157 |
158 | public Load click(@NonNull PendingIntent pendingIntent) {
159 | this.builder.setContentIntent(pendingIntent);
160 | return this;
161 | }
162 |
163 | @SuppressLint("ResourceType")
164 | public Load color(@ColorRes int color) {
165 | if (color <= 0) {
166 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
167 | }
168 |
169 | Context context = ZadakNotification.mSingleton.mContext;
170 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
171 | this.builder.setColor(context.getColor(color));
172 | } else {
173 | this.builder.setColor(context.getResources().getColor(color));
174 | }
175 | return this;
176 | }
177 |
178 | public Custom custom() {
179 | notificationShallContainAtLeastThoseSmallIconValid();
180 | return new Custom(builder, notificationId, title, message, messageSpanned, smallIcon, tag);
181 | }
182 |
183 | public Load dismiss(@NonNull Class> activity, Bundle bundle) {
184 | this.builder.setDeleteIntent(new DismissPendingIntentActivity(activity, bundle, notificationId)
185 | .onSettingPendingIntent());
186 | return this;
187 | }
188 |
189 | public Load dismiss(@NonNull Class> activity) {
190 | dismiss(activity, null);
191 | return this;
192 | }
193 |
194 | public Load dismiss(@NonNull Bundle bundle) {
195 | this.builder.setDeleteIntent(new DismissPendingIntentBroadCast(bundle, notificationId).onSettingPendingIntent
196 | ());
197 | return this;
198 | }
199 |
200 |
201 | public Load dismiss(@NonNull PendingIntentNotification pendingIntentNotification) {
202 | this.builder.setDeleteIntent(pendingIntentNotification.onSettingPendingIntent());
203 | return this;
204 | }
205 |
206 | public Load dismiss(@NonNull PendingIntent pendingIntent) {
207 | this.builder.setDeleteIntent(pendingIntent);
208 | return this;
209 | }
210 |
211 | public Load flags(int defaults) {
212 | this.builder.setDefaults(defaults);
213 | return this;
214 | }
215 |
216 | public Load group(@NonNull String groupKey) {
217 | if (groupKey.trim().length() == 0) {
218 |
219 | throw new IllegalArgumentException("Group Key Must Not Be Empty!");
220 | }
221 |
222 | this.builder.setGroup(groupKey);
223 | return this;
224 | }
225 |
226 | public Load groupSummary(boolean groupSummary) {
227 | this.builder.setGroupSummary(groupSummary);
228 | return this;
229 | }
230 |
231 | public Load identifier(int identifier) {
232 | if (identifier <= 0) {
233 |
234 | throw new IllegalStateException("Identifier Should Not Be Less Than Or Equal To Zero!");
235 | }
236 |
237 | this.notificationId = identifier;
238 | return this;
239 | }
240 |
241 | public Load inboxStyle(@NonNull String[] inboxLines, @NonNull String title, String summary) {
242 | if (inboxLines.length <= 0) {
243 | throw new IllegalArgumentException("Inbox Lines Must Have At Least One Text!");
244 | }
245 |
246 | if (title.trim().length() == 0) {
247 | throw new IllegalArgumentException("Title Must Not Be Empty!");
248 | }
249 |
250 | NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
251 | for (String inboxLine : inboxLines) {
252 | inboxStyle.addLine(inboxLine);
253 | }
254 | inboxStyle.setBigContentTitle(title);
255 | if (summary != null) {
256 | inboxStyle.setSummaryText(summary);
257 | }
258 | this.builder.setStyle(inboxStyle);
259 | return this;
260 | }
261 |
262 | public Load largeIcon(@NonNull Bitmap bitmap) {
263 | this.builder.setLargeIcon(bitmap);
264 | return this;
265 | }
266 |
267 | @SuppressLint("ResourceType")
268 | public Load largeIcon(@DrawableRes int largeIcon) {
269 | if (largeIcon <= 0) {
270 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
271 | }
272 |
273 | Bitmap bitmap = BitmapFactory.decodeResource(ZadakNotification.mSingleton.mContext.getResources(), largeIcon);
274 | this.builder.setLargeIcon(bitmap);
275 | return this;
276 | }
277 |
278 | public Load lights(int color, int ledOnMs, int ledOfMs) {
279 | if (ledOnMs < 0) {
280 | throw new IllegalStateException("Led On Milliseconds Invalid!");
281 | }
282 |
283 | if (ledOfMs < 0) {
284 | throw new IllegalStateException("Led Off Milliseconds Invalid!");
285 | }
286 |
287 | this.builder.setLights(color, ledOnMs, ledOfMs);
288 |
289 | return this;
290 | }
291 |
292 | @SuppressLint("ResourceType")
293 | public Load message(@StringRes int message) {
294 | if (message <= 0) {
295 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
296 | }
297 |
298 | this.message = ZadakNotification.mSingleton.mContext.getResources().getString(message);
299 | this.builder.setContentText(this.message);
300 | return this;
301 | }
302 |
303 | public Load message(@NonNull String message) {
304 |
305 | if (message.trim().length() == 0) {
306 | throw new IllegalArgumentException("Message Must Not Be Empty!");
307 |
308 | }
309 |
310 | this.message = message;
311 | this.builder.setContentText(message);
312 | return this;
313 | }
314 |
315 | public Load message(@NonNull Spanned messageSpanned) {
316 | if (messageSpanned.length() == 0) {
317 | throw new IllegalArgumentException("Message Must Not Be Empty!");
318 | }
319 |
320 | this.messageSpanned = messageSpanned;
321 | this.builder.setContentText(messageSpanned);
322 | return this;
323 | }
324 |
325 | public Load notificationChannelId(final String channelId) {
326 | this.notificationChannelId = channelId;
327 | this.builder.setChannelId(channelId);
328 | return this;
329 | }
330 |
331 | public Load number(int number) {
332 | this.builder.setNumber(number);
333 | return this;
334 | }
335 |
336 | public Load ongoing(boolean ongoing) {
337 | this.builder.setOngoing(ongoing);
338 | return this;
339 | }
340 |
341 | public Load onlyAlertOnce(boolean onlyAlertOnce) {
342 | this.builder.setOnlyAlertOnce(onlyAlertOnce);
343 | return this;
344 | }
345 |
346 | public Load priority(int priority) {
347 | if (priority <= 0) {
348 | throw new IllegalArgumentException("Priority Should Not Be Less Than Or Equal To Zero!");
349 | }
350 | this.builder.setPriority(priority);
351 | return this;
352 | }
353 |
354 | public Progress progress() {
355 | notificationShallContainAtLeastThoseSmallIconValid();
356 | return new Progress(builder, notificationId, tag);
357 | }
358 |
359 | public Simple simple() {
360 | notificationShallContainAtLeastThoseSmallIconValid();
361 | return new Simple(builder, notificationId, tag);
362 | }
363 |
364 | public Load smallIcon(@DrawableRes int smallIcon) {
365 | this.smallIcon = smallIcon;
366 | this.builder.setSmallIcon(smallIcon);
367 | return this;
368 | }
369 |
370 | public Load sound(@NonNull Uri sound) {
371 | this.builder.setSound(sound);
372 | return this;
373 | }
374 |
375 | public Load tag(@NonNull String tag) {
376 | this.tag = tag;
377 | return this;
378 | }
379 |
380 | @SuppressLint("ResourceType")
381 | public Load ticker(@StringRes int ticker) {
382 | if (ticker <= 0) {
383 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
384 | }
385 |
386 | this.builder.setTicker(ZadakNotification.mSingleton.mContext.getResources().getString(ticker));
387 |
388 | return this;
389 | }
390 |
391 | public Load ticker(String ticker) {
392 | if (ticker == null) {
393 | throw new IllegalStateException("Ticker Must Not Be Null!");
394 |
395 |
396 |
397 | }
398 |
399 | if (ticker.trim().length() == 0) {
400 | throw new IllegalArgumentException("Ticker Must Not Be Empty!");
401 |
402 | }
403 |
404 | this.builder.setTicker(ticker);
405 |
406 | return this;
407 | }
408 |
409 | @SuppressLint("ResourceType")
410 | public Load title(@StringRes int title) {
411 | if (title <= 0) {
412 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
413 | }
414 |
415 | this.title = ZadakNotification.mSingleton.mContext.getResources().getString(title);
416 | this.builder.setContentTitle(this.title);
417 | return this;
418 | }
419 |
420 | public Load title(String title) {
421 | if (title == null) {
422 | throw new IllegalStateException("Title Must Not Be Null!");
423 | }
424 |
425 | if (title.trim().length() == 0) {
426 | throw new IllegalArgumentException("Title Must Not Be Empty!");
427 |
428 | }
429 |
430 | this.title = title;
431 | this.builder.setContentTitle(this.title);
432 | return this;
433 | }
434 |
435 | public Load vibrate(@NonNull long[] vibrate) {
436 | for (long aVibrate : vibrate) {
437 | if (aVibrate <= 0) {
438 | throw new IllegalArgumentException("Vibrate Time " + aVibrate + " Invalid!");
439 | }
440 | }
441 |
442 | this.builder.setVibrate(vibrate);
443 |
444 | return this;
445 | }
446 |
447 | public Wear wear() {
448 | notificationShallContainAtLeastThoseSmallIconValid();
449 | return new Wear(builder, notificationId, tag);
450 | }
451 |
452 | public Load when(long when) {
453 | if (when <= 0) {
454 | throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
455 | }
456 |
457 | this.builder.setWhen(when);
458 | return this;
459 | }
460 |
461 | private void notificationShallContainAtLeastThoseSmallIconValid() {
462 | if (smallIcon <= 0) {
463 | throw new IllegalArgumentException("This is required. Notifications with an invalid icon resource will " +
464 | "not be shown.");
465 | }
466 | }
467 | }
--------------------------------------------------------------------------------