From 5a1fc842bf9b9cfe56d8674707dd9f0cb67f2278 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Thu, 23 May 2024 16:47:15 +0200 Subject: [PATCH] fix(android): fix Actionbar backgroundImage doc and improve setter --- .../appcelerator/titanium/proxy/ActionBarProxy.java | 12 ++++++++++++ apidoc/Titanium/Android/ActionBar.yml | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java b/android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java index 988e87c6746..3d29ce309e2 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java +++ b/android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java @@ -15,6 +15,7 @@ import org.appcelerator.titanium.TiC; import org.appcelerator.titanium.util.TiConvert; import org.appcelerator.titanium.util.TiUIHelper; +import org.appcelerator.titanium.view.TiDrawableReference; @SuppressWarnings("deprecation") @Kroll.proxy(propertyAccessors = { TiC.PROPERTY_ON_HOME_ICON_ITEM_SELECTED, TiC.PROPERTY_CUSTOM_VIEW }) @@ -102,6 +103,17 @@ public void setBackgroundImage(String url) actionBar.setDisplayShowTitleEnabled(showTitleEnabled); actionBar.setBackgroundDrawable(backgroundImage); + } else { + // fallback check with TiDrawableReference + TiDrawableReference source = TiDrawableReference.fromUrl(this, url); + if (source.getDrawable() != null) { + actionBar.setDisplayShowTitleEnabled(!showTitleEnabled); + actionBar.setDisplayShowTitleEnabled(showTitleEnabled); + actionBar.setBackgroundDrawable(source.getDrawable()); + } else { + // fail - show error + Log.e(TAG, "Image " + url + " not found"); + } } } diff --git a/apidoc/Titanium/Android/ActionBar.yml b/apidoc/Titanium/Android/ActionBar.yml index 2450257cbde..db9f36e9bb5 100644 --- a/apidoc/Titanium/Android/ActionBar.yml +++ b/apidoc/Titanium/Android/ActionBar.yml @@ -55,6 +55,15 @@ examples: ``` + + `app/controllers/index.js`: + ``` + function doMenuClick() {} + function openSettings() {} + function doSearch() {} + $.index.open(); + ``` + `app/styles/index.tss`: ``` "MenuItem": { @@ -85,7 +94,7 @@ examples: win.activity.onCreate = () => { const actionBar = win.activity.actionBar; if (actionBar) { - actionBar.backgroundImage = "/bg.png"; + actionBar.backgroundImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'bg.png').nativePath; actionBar.title = "New Title"; actionBar.onHomeIconItemSelected = () => { Ti.API.info("Home icon clicked!");