Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
d9bb523c
Commit
d9bb523c
authored
Oct 11, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented attachments and big picture style for Android
parent
d85f6af1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
15 deletions
+53
-15
Builder.java
src/android/notification/Builder.java
+15
-13
Options.java
src/android/notification/Options.java
+38
-2
No files found.
src/android/notification/Builder.java
View file @
d9bb523c
...
@@ -24,8 +24,10 @@ package de.appplant.cordova.plugin.notification;
...
@@ -24,8 +24,10 @@ package de.appplant.cordova.plugin.notification;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.Random
;
import
de.appplant.cordova.plugin.notification.activity.ClickActivity
;
import
de.appplant.cordova.plugin.notification.activity.ClickActivity
;
...
@@ -130,20 +132,24 @@ public class Builder {
...
@@ -130,20 +132,24 @@ public class Builder {
* @param builder Local notification builder instance
* @param builder Local notification builder instance
*/
*/
private
void
applyStyle
(
NotificationCompat
.
Builder
builder
)
{
private
void
applyStyle
(
NotificationCompat
.
Builder
builder
)
{
List
<
Bitmap
>
pics
=
options
.
getAttachments
();
String
summary
=
options
.
getSummary
();
String
summary
=
options
.
getSummary
();
String
text
=
options
.
getText
();
String
text
=
options
.
getText
();
if
(
summary
==
null
&&
text
==
null
)
if
(
pics
.
size
()
>
0
)
{
NotificationCompat
.
BigPictureStyle
style
=
new
NotificationCompat
.
BigPictureStyle
(
builder
)
.
setSummaryText
(
summary
==
null
?
text
:
summary
)
.
bigPicture
(
pics
.
get
(
0
));
builder
.
setStyle
(
style
);
return
;
return
;
}
if
(
text
.
contains
(
"\n"
))
{
if
(
text
!=
null
&&
text
.
contains
(
"\n"
))
{
NotificationCompat
.
InboxStyle
style
=
NotificationCompat
.
InboxStyle
style
=
new
NotificationCompat
.
InboxStyle
(
builder
)
new
NotificationCompat
.
InboxStyle
(
builder
)
.
setBigContentTitle
(
options
.
getTitle
());
.
setSummaryText
(
summary
);
if
(
summary
!=
null
)
{
style
.
setSummaryText
(
summary
);
}
for
(
String
line
:
text
.
split
(
"\n"
))
{
for
(
String
line
:
text
.
split
(
"\n"
))
{
style
.
addLine
(
line
);
style
.
addLine
(
line
);
...
@@ -153,18 +159,14 @@ public class Builder {
...
@@ -153,18 +159,14 @@ public class Builder {
return
;
return
;
}
}
if
(
summary
==
null
&&
text
.
length
()
<
45
)
if
(
text
==
null
||
summary
==
null
&&
text
.
length
()
<
45
)
return
;
return
;
NotificationCompat
.
BigTextStyle
style
=
NotificationCompat
.
BigTextStyle
style
=
new
NotificationCompat
.
BigTextStyle
(
builder
)
new
NotificationCompat
.
BigTextStyle
(
builder
)
.
set
BigContentTitle
(
options
.
getTitle
()
)
.
set
SummaryText
(
summary
)
.
bigText
(
text
);
.
bigText
(
text
);
if
(
summary
!=
null
)
{
style
.
setSummaryText
(
summary
);
}
builder
.
setStyle
(
style
);
builder
.
setStyle
(
style
);
}
}
...
...
src/android/notification/Options.java
View file @
d9bb523c
...
@@ -29,6 +29,11 @@ import android.support.v4.app.NotificationCompat;
...
@@ -29,6 +29,11 @@ import android.support.v4.app.NotificationCompat;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.io.IOException
;
import
java.lang.reflect.Array
;
import
java.util.ArrayList
;
import
java.util.List
;
import
de.appplant.cordova.plugin.notification.util.AssetUtil
;
import
de.appplant.cordova.plugin.notification.util.AssetUtil
;
import
static
android
.
support
.
v4
.
app
.
NotificationCompat
.
DEFAULT_LIGHTS
;
import
static
android
.
support
.
v4
.
app
.
NotificationCompat
.
DEFAULT_LIGHTS
;
...
@@ -249,7 +254,7 @@ public class Options {
...
@@ -249,7 +254,7 @@ public class Options {
* Sound file path for the local notification.
* Sound file path for the local notification.
*/
*/
public
Uri
getSound
()
{
public
Uri
getSound
()
{
return
assets
.
parse
(
options
.
optString
(
"sound"
));
return
assets
.
parse
(
options
.
optString
(
"sound"
,
null
));
}
}
/**
/**
...
@@ -448,7 +453,38 @@ public class Options {
...
@@ -448,7 +453,38 @@ public class Options {
* The summary for inbox style notifications.
* The summary for inbox style notifications.
*/
*/
String
getSummary
()
{
String
getSummary
()
{
return
options
.
optString
(
"summary"
);
return
options
.
optString
(
"summary"
,
null
);
}
/**
* Image attachments for image style notifications.
*
* @return For now it only returns the first item as Android does not
* support multiple attachments like iOS.
*/
List
<
Bitmap
>
getAttachments
()
{
JSONArray
paths
=
options
.
optJSONArray
(
"attachments"
);
List
<
Bitmap
>
pics
=
new
ArrayList
<
Bitmap
>();
if
(
paths
==
null
)
return
pics
;
for
(
int
i
=
0
;
i
<
paths
.
length
();
i
++)
{
Uri
uri
=
assets
.
parse
(
paths
.
optString
(
i
));
if
(
uri
==
Uri
.
EMPTY
)
continue
;
try
{
Bitmap
pic
=
assets
.
getIconFromUri
(
uri
);
pics
.
add
(
pic
);
break
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
pics
;
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment