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
2ca56e6c
Commit
2ca56e6c
authored
Oct 13, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for input actions on Android
parent
c52bd8c8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
35 deletions
+75
-35
LocalNotification.java
src/android/LocalNotification.java
+1
-1
Action.java
src/android/notification/Action.java
+51
-30
ActionGroup.java
src/android/notification/ActionGroup.java
+13
-1
Builder.java
src/android/notification/Builder.java
+10
-3
No files found.
src/android/LocalNotification.java
View file @
2ca56e6c
...
...
@@ -607,7 +607,7 @@ public class LocalNotification extends CordovaPlugin {
String
js
=
"cordova.plugins.notification.local.core.fireEvent("
+
"\""
+
event
+
"\","
+
params
+
")"
;
sendJavascript
(
js
);
//
sendJavascript(js);
}
/**
...
...
src/android/notification/Action.java
View file @
2ca56e6c
...
...
@@ -22,7 +22,9 @@
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
android.content.Context
;
import
android.support.v4.app.RemoteInput
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
de.appplant.cordova.plugin.notification.util.AssetUtil
;
...
...
@@ -38,17 +40,11 @@ final class Action {
// Key name for bundled extras
static
final
String
EXTRA
=
"NOTIFICATION_ACTION_ID"
;
// The
ID of the action
private
final
String
id
;
// The
application context
private
final
Context
context
;
// The title for the action
private
final
String
title
;
// The icon for the action
private
final
int
icon
;
// The launch flag for the action
private
final
boolean
launch
;
// The action spec
private
final
JSONObject
options
;
/**
* Structure to encapsulate a named action that can be shown as part of
...
...
@@ -58,57 +54,81 @@ final class Action {
* @param options The action options.
*/
Action
(
Context
context
,
JSONObject
options
)
{
this
.
icon
=
parseIcon
(
context
,
options
.
optString
(
"icon"
));
this
.
title
=
options
.
optString
(
"title"
);
this
.
id
=
options
.
optString
(
"id"
,
title
);
this
.
launch
=
options
.
optBoolean
(
"launch"
,
false
);
this
.
context
=
context
;
this
.
options
=
options
;
}
/**
* Gets the ID for the action.
*/
public
String
getId
()
{
return
id
;
return
options
.
optString
(
"id"
,
getTitle
())
;
}
/**
* Gets the Title for the action.
*/
public
String
getTitle
()
{
return
title
;
return
options
.
optString
(
"title"
,
"unknown"
)
;
}
/**
* Gets the icon for the action.
*/
public
int
getIcon
()
{
return
icon
;
AssetUtil
assets
=
AssetUtil
.
getInstance
(
context
);
String
resPath
=
options
.
optString
(
"icon"
);
int
resId
=
assets
.
getResId
(
resPath
);
if
(
resId
==
0
)
{
resId
=
android
.
R
.
drawable
.
screen_background_dark
;
}
return
resId
;
}
/**
* Gets the value of the launch flag.
*/
public
boolean
isLaunchingApp
()
{
return
launch
;
return
options
.
optBoolean
(
"launch"
,
false
)
;
}
/**
* Parse the uri into a resource id.
*
* @param context The application context.
* @param resPath The resource path.
*
* @return The resource id.
* Gets the type for the action.
*/
private
int
parseIcon
(
Context
context
,
String
resPath
)
{
AssetUtil
assets
=
AssetUtil
.
getInstance
(
context
);
int
resId
=
assets
.
getResId
(
resPath
);
boolean
isWithInput
()
{
String
type
=
options
.
optString
(
"type"
);
return
type
.
equals
(
"input"
);
}
if
(
resId
==
0
)
{
resId
=
android
.
R
.
drawable
.
screen_background_dark
;
/**
* Gets the input config in case of the action is of type input.
*/
RemoteInput
getInput
()
{
return
new
RemoteInput
.
Builder
(
getId
())
.
setLabel
(
options
.
optString
(
"emptyText"
))
.
setAllowFreeFormInput
(
options
.
optBoolean
(
"editable"
,
true
))
.
setChoices
(
getChoices
())
.
build
();
}
/**
* List of possible choices for input actions.
*/
private
String
[]
getChoices
()
{
JSONArray
opts
=
options
.
optJSONArray
(
"choices"
);
if
(
opts
==
null
)
return
null
;
String
[]
choices
=
new
String
[
opts
.
length
()];
for
(
int
i
=
0
;
i
<
choices
.
length
;
i
++)
{
choices
[
i
]
=
opts
.
optString
(
i
);
}
return
resId
;
return
choices
;
}
}
\ No newline at end of file
src/android/notification/ActionGroup.java
View file @
2ca56e6c
...
...
@@ -22,6 +22,7 @@
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
android.content.Context
;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
...
...
@@ -31,6 +32,9 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
android
.
os
.
Build
.
VERSION_CODES
.
N
;
public
final
class
ActionGroup
{
// Default action group id
...
...
@@ -86,9 +90,17 @@ public final class ActionGroup {
for
(
int
i
=
0
;
i
<
list
.
length
();
i
++)
{
JSONObject
opts
=
list
.
optJSONObject
(
i
);
String
type
=
opts
.
optString
(
"type"
,
"button"
);
if
(
type
.
equals
(
"input"
)
&&
SDK_INT
<
N
)
{
Log
.
w
(
"Action"
,
"Type input is not supported"
);
continue
;
}
if
(!
opts
.
optString
(
"type"
,
"button"
).
equals
(
"button"
))
if
(!(
type
.
equals
(
"button"
)
||
type
.
equals
(
"input"
)))
{
Log
.
w
(
"Action"
,
"Unknown type: "
+
type
);
continue
;
}
actions
.
add
(
new
Action
(
context
,
opts
));
}
...
...
src/android/notification/Builder.java
View file @
2ca56e6c
...
...
@@ -229,14 +229,21 @@ public final class Builder {
*/
private
void
applyActions
(
NotificationCompat
.
Builder
builder
)
{
Action
[]
actions
=
options
.
getActions
();
NotificationCompat
.
Action
.
Builder
btn
;
if
(
actions
==
null
||
actions
.
length
==
0
)
return
;
for
(
Action
action
:
actions
)
{
builder
.
addAction
(
action
.
getIcon
(),
action
.
getTitle
(),
getPendingIntentForAction
(
action
));
btn
=
new
NotificationCompat
.
Action
.
Builder
(
action
.
getIcon
(),
action
.
getTitle
(),
getPendingIntentForAction
(
action
));
if
(
action
.
isWithInput
())
{
btn
.
addRemoteInput
(
action
.
getInput
());
}
builder
.
addAction
(
btn
.
build
());
}
}
...
...
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