Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't setHomeAsUpIcon in 1.3.6 using Alloy MVC #68

Closed
IvoPereira opened this issue May 4, 2015 · 19 comments
Closed

Can't setHomeAsUpIcon in 1.3.6 using Alloy MVC #68

IvoPereira opened this issue May 4, 2015 · 19 comments
Assignees

Comments

@IvoPereira
Copy link

Hello,

I'm using Alloy MVC, and inside of one of my controllers, I'm using the following:

$.win.addEventListener("open", function() {

    if (Ti.Platform.osname === "android") {
        if (!$.win.activity) {
            Ti.API.error("Can't access action bar on a lightweight window.");
        } else {
            var abx = require('com.alcoapps.actionbarextras');
            abx.window = $.win;

            actionBar = $.win.activity.actionBar;
            if (actionBar) {
                abx.setTitle("Example");
        abx.setHomeAsUpIcon('/images/icon_menu.png');
            }

        }
    }
});

I do have an image in /PROJECT_NAME/app/assets/images/icon_menu.png, and my controller is located in /PROJECT_NAME/app/controllers/example.js.

Just to note that all the others images for example in Titanium ImageViews load fine, using the same schema.

When starting my application, the title do change to "Example", however the homeAsUpIcon does not change and an error is shown in console:

[ERROR] ActionbarextrasModule: (main) [273,11626] Couldn't resolve appdata-private://PROJECT_NAME/android/images//icon_menu.png

I've already tried to play with slashes and some folder derivations in icon location, but I am not being able to get it work. Is it possible this is a bug in the module?

Thanks

@manumaticx
Copy link
Collaborator

Hi @IvoPereira

Are you using Titanium 4.0.X ?

Maybe it's a bug. Your code looks good. I wonder if providing a density-independent image resource would solve this because the same thing is working in the example. I'd need to change how to resolve the image then. Could be worth a try.

@IvoPereira
Copy link
Author

Hello @manumaticx,

I'm using Titanium Studio v. 3.4.1.201410281727 and Titanium SDK 3.5.1.GA.

I'm testing on a 4.2.2 device.

That snippet is working in the example, however the example does not use MVC and its folder structure (controllers, models, views), and is only based in an app.js file at root. Possibly may be that related to the problem locating the files?

As soon as I get office I will try with some density-independent image resources, and I'll let you know the result.

Thanks.

@manumaticx
Copy link
Collaborator

There shouldn't be a difference when using Alloy because Alloy creates a classic project with the same folder structure.

I've just tested an fixed-density image and I do get the same error:
ActionbarextrasModule: (main) [2,3204] Couldn't resolve /images/icon_menu.png

I recommend you using res-mdpi, res-hdpi, res-xhdpi, res-xxhdpi resources for icons. This will solve your issue.

But I also will try to resolve resources within the /images/ directory.

@IvoPereira
Copy link
Author

Hey @manumaticx,

Thanks for the feedback. I was trying to follow your suggestion, so I've put the image inside all of the folders you mentioned, using the path:
/PROJECT_NAME/app/assets/images/res-hdpi
/PROJECT_NAME/app/assets/images/res-mdpi
/PROJECT_NAME/app/assets/images/res-xhdpi
/PROJECT_NAME/app/assets/images/res-xxhdpi

However, it seemed to change something in the location where it was looking for the file, but it was still not able to find it (and the files were moved to Resources folder as expected).

Couldn't resolve

@manumaticx
Copy link
Collaborator

Hm, I'm not sure what's going on here!

I've just created a fresh new Alloy app with Titanium 3.5.1.GA and ABX 1.6.3 to test this. But I am not able to reproduce this error.

The resource path in your log is also very strange. It should actually log the path that was passed to setHomeAsUpIcon, not the resolved path. I will have to do some more testing in order to fix this. Hopefully I can come up with a solution here.

If you find anything that could help me to find the reason for this, please let me know.

@manumaticx manumaticx added the bug label May 5, 2015
@manumaticx manumaticx added this to the 1.7.0 milestone May 5, 2015
@manumaticx manumaticx self-assigned this May 5, 2015
@IvoPereira
Copy link
Author

I'll be happy to assist you debugging the problem @manumaticx.

I've tried with a live device LG-G2 using Ti-Shadow (and without it - through TitaniumStudio directly).

The image I'm using is this one: http://i.imgur.com/AR7zIc8.png

Let me know if you need anything else.

@ndastur
Copy link

ndastur commented Jun 2, 2015

@manumaticx strange but I get a similar error

[ERROR] ActionbarextrasModule: (main) [1441,2453] Couldn't resolve ic_menu_black_24dp.png

and the ic_menu_black_24dp.png is in app/assets/android. Also tried with a / prefix and still not found

@manumaticx
Copy link
Collaborator

@ndastur as stated in the above comment I'd recommend using res-mdpi, res-hdpi, res-xhdpi, res-xxhdpi - this probably solves the error

@ndastur
Copy link

ndastur commented Jun 2, 2015

@manumaticx thanks. I have been looking into the code and I think it is because you are using the getResourceId helper function. Looking deeper into the Appc source this seems to be a deeper level function.

Looking at how Appc resolve the setIcon in their actionbar implementation
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java
I think some higher level SDK helper function is required.

@ndastur
Copy link

ndastur commented Jun 2, 2015

Specific bit of code that might help is

private Drawable getDrawableFromUrl(String url)
    {
        TiUrl imageUrl = new TiUrl((String) url);
        TiFileHelper tfh = new TiFileHelper(TiApplication.getInstance());
        return tfh.loadDrawable(imageUrl.resolve(), false);
    }

@manumaticx
Copy link
Collaborator

@ndastur Thank you for this. Do you think there is a chance that you could build the module and test this?

@ChanakyaSrinivas
Copy link

Unable to setHomeAsUpIcon with titanium 4.0.X

Can any one help me out.

@manumaticx
Copy link
Collaborator

@ChanakyaSrinivas Hi there, I need some more info! This is not considered as a bug until you instruct me how to reproduce the issue.

@ChanakyaSrinivas
Copy link

Environments:
Tiatanium sdk 4.1.0
MVC Alloy 1.6.2

code:
mytest

output:

output

Not getting any error related to setHomeAsUpIcon.
But Icon is not visible left side corner.

@manumaticx
Copy link
Collaborator

@ChanakyaSrinivas try adding actionBar.displayHomeAsUp = true; before the line where you set the icon

if (actionBar){
  actionBar.displayHomeAsUp = true;
  abx.setTitle("Example");
  abx.setHomeAsUpIcon("/images/drawericon.png");
}

@ChanakyaSrinivas
Copy link

As per your suggestion changed my code.
It's working fine.

@manumaticx
Copy link
Collaborator

Great. Nice to hear.

So I think I can close this issue here since setHomeAsUpIcon works as expected and the behavior described in the original question is not reproducible.

Please feel free to reopen if you can provide test code to reproduce this issue.

@ChanakyaSrinivas
Copy link

Hi All,

Module is not working for Titanium SDK 5.3.1GA and Alloy 1.8.7

Environments:
Npm Version = 2.11.3
Titanium CLI Version = 5.0.8
Titanium SDK Version = 5.3.1.GA
Alloy Version = 1.8.7

Error:

[ERROR] : TiApplication: java.lang.ClassCastException: org.appcelerator.titanium.TiActivity cannot be cast to android.support.v7.app.ActionBarActivity [ERROR] : TiApplication: at com.alcoapps.actionbarextras.ActionbarextrasModule.getActionBar(ActionbarextrasModule.java:117) [ERROR] : TiApplication: at com.alcoapps.actionbarextras.ActionbarextrasModule.handleSetHomeAsUpIcon(ActionbarextrasModule.java:523) [ERROR] : TiApplication: at com.alcoapps.actionbarextras.ActionbarextrasModule.handleMessage(ActionbarextrasModule.java:175) [ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:98) [ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:148) [ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5417) [ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Native Method) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

@manumaticx
Copy link
Collaborator

@ChanakyaSrinivas Try updating the Module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants