Skip to content

Commit

Permalink
Merge pull request #6992 from ashcoding/TIMOB-15570
Browse files Browse the repository at this point in the history
[TIMOB-15570] Android: Add support for largeIcon in Titanium.Android.…
  • Loading branch information
hieupham007 committed Jul 29, 2015
2 parents 0e3369d + 94ebadc commit 4ff99e0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Expand Up @@ -22,6 +22,8 @@
import ti.modules.titanium.android.PendingIntentProxy;
import ti.modules.titanium.android.RemoteViewsProxy;
import android.app.Notification;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
Expand Down Expand Up @@ -68,6 +70,9 @@ public void handleCreationDict(KrollDict d)
if (d.containsKey(TiC.PROPERTY_ICON)) {
setIcon(d.get(TiC.PROPERTY_ICON));
}
if (d.containsKey(TiC.PROPERTY_LARGE_ICON)) {
setLargeIcon(d.get(TiC.PROPERTY_LARGE_ICON));
}
if (d.containsKey(TiC.PROPERTY_TICKER_TEXT)) {
setTickerText(TiConvert.toString(d, TiC.PROPERTY_TICKER_TEXT));
}
Expand Down Expand Up @@ -147,6 +152,25 @@ public void setIcon(Object icon)
setProperty(TiC.PROPERTY_ICON, icon);
}

@Kroll.method @Kroll.setProperty
public void setLargeIcon(Object icon)
{
if(icon instanceof Number) {
Bitmap largeIcon = BitmapFactory.decodeResource(TiApplication.getInstance().getResources(), ((Number)icon).intValue());
notificationBuilder.setLargeIcon(largeIcon);
}else{
String iconUrl = TiConvert.toString(icon);
if (iconUrl == null) {
Log.e(TAG, "Url is null");
return;
}
String iconFullUrl = resolveUrl(null, iconUrl);
Bitmap largeIcon = BitmapFactory.decodeResource(TiApplication.getInstance().getResources(), TiUIHelper.getResourceId(iconFullUrl));
notificationBuilder.setLargeIcon(largeIcon);
}
setProperty(TiC.PROPERTY_LARGE_ICON, icon);
}

@Kroll.method @Kroll.setProperty
public void setVisibility(int visibility)
{
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Expand Up @@ -1526,6 +1526,11 @@ public class TiC
*/
public static final String PROPERTY_KIND = "kind";

/**
* @module.api
*/
public static final String PROPERTY_LARGE_ICON = "largeIcon";

/**
* @module.api
*/
Expand Down
29 changes: 29 additions & 0 deletions apidoc/Titanium/Android/Notification.yml
Expand Up @@ -210,6 +210,35 @@ properties:
Android resources by ID.
type: [Number,String]

- name: largeIcon
summary:
Add a large icon to the notification (and the ticker on some devices)
specified as an Android resource ID, or a local URL to a density-specific image.
description: |
If specified as a URL, the icon must be placed in one of the density-specific
folders under `Resources/android/images`. For example, if your icon is called
`my_large_icon.png`, you would create high- and medium-density versions of the icons
with the following paths:
Resources/android/images/res-hdpi/my_large_icon.png
Resources/android/images/res-mdpi/my_large_icon.png
To access this large icon, you'd use the URL '/images/my_large_icon.png'.
To access the same large icon using an Android resource ID, place the icon in:
platform/android/res/drawable/my_large_icon.png
This large icon's resource ID can be referenced through the <Titanium.App.Android.R>
object:
icon: Ti.App.Android.R.drawable.my_large_icon,
See <Titanium.App.Android.R> for more information on accessing
Android resources by ID.
type: [Number,String]
since: "4.2.0"

- name: ledARGB
summary: The color for the LED to blink.
type: Number
Expand Down

0 comments on commit 4ff99e0

Please sign in to comment.