Skip to content

Commit f641555

Browse files
committed
Merge pull request #3 from lazaromenezes/master
add support for native android icons
2 parents 5e3ce07 + a466951 commit f641555

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,7 @@ FakesAssemblies/
201201

202202
.vs
203203
.vs/
204-
nativescript-fab.sln
204+
nativescript-fab.sln
205+
206+
# Demo application build files
207+
demo/platforms/*

fab.android.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**************************************************************************************
2-
* Made for the {N} community by Brad Martin @BradWayneMartin
3-
* Thanks to Lazaro Danillo for his contributions - https://github.com/lazaromenezes
2+
* Made for the {N} community by Brad Martin @BradWayneMartin
3+
* Thanks to Lazaro Danillo for his contributions - https://github.com/lazaromenezes
44
* https://twitter.com/BradWayneMartin
55
* https://github.com/bradmartin
66
* Pull requests are welcome. Enjoy!
77
*************************************************************************************/
88

99
var common = require("./fab-common");
10-
var utils = require("utils/utils");
10+
var ImageSource = require("image-source");
1111

1212
require("utils/module-merge").merge(common, module.exports);
1313

@@ -30,12 +30,17 @@
3030
this._android.setBackgroundTintList(android.content.res.ColorStateList.valueOf(this.backColor.android));
3131

3232
if(this.icon){
33-
var res = utils.ad.getApplicationContext().getResources();
34-
if(res){
35-
var identifier = res.getIdentifier(this.icon, 'drawable', utils.ad.getApplication().getPackageName());
36-
var bitmapDrawable = res.getDrawable(identifier);
37-
this._android.setImageDrawable(bitmapDrawable);
33+
iconDrawable = null;
34+
35+
if(ImageSource.isFileOrResourcePath(this.icon))
36+
iconDrawable = ImageSource.fromFileOrResource(this.icon);
37+
else{
38+
var drawableId = android.content.res.Resources.getSystem().getIdentifier(this.icon, "drawable", "android");
39+
iconDrawable = android.content.res.Resources.getSystem().getDrawable(drawableId);
3840
}
41+
42+
if(iconDrawable != null)
43+
this._android.setImageDrawable(iconDrawable);
3944
}
4045

4146
var that = new WeakRef(this);

0 commit comments

Comments
 (0)