简体   繁体   中英

Create custom drawable resources to handle different logos

I'm building an app for a group of three different societies. Each society of the group have its own web site that is a clone of the others, exception made for logos and domains. So, in example, I have:

logoA.jpeg

logoB.jpeg

logoC.jpeg

For soc. A, B and C.

http: // socA.it /homepage/default.aspx

http: // socB.it /homepage/default.aspx

http: // socC.it /homepage/default.aspx

for home page links and so on. Layouts of the sites are exactly the same.

What I have to do with my app is to retrieve data from the pages of the sites. In the start activity of my app the registered user can choose on which site logins and works. Once he is logged in he can get the pieces of information he needs from the site/society he choose trhows my app.

I obviously built a single app to retrieve data from all the sites, but I'm looking for an elegant (and correct of course) way to handle the different domains/logos. As concern domains I save the one the user choose at login time in the user preferences and I retrieve it as base_url (the domain) when I need it.

The question is: how can I handle logos? I have three different logos that can be shown, and I have a copy of them for each resolution in drawable* folders. What I think I can do is to add an if statement in each onCreate event of each activity that check the user preference and show the correct logo (or use a method getMyLogo() created somewhere else), but it's boring.. Could it be better to create a custom drawable folder for each case to handle all different scenarios:

drawable drawable-A-ldpi drawable-A-mdpi drawable-A-hdpi drawable-B.ldpi... ?

Any suggestion is appreciated.

As far as i know this is not possible, the cleanest way is to have a class called something in the lines of SocietyHelper with static methods for getLogo() and getUrl(). The only thing that is not "clean" with this is that you cannot define the logo in xml. If your logo is always in an imageview you could however make an ImageView subclass maybe called LogoImageView which really just initializes the ImageView with the correct logo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM