Android drawable resources: how to change color scheme based on version of application - android-resources

I am trying to implement two different versions of the same application, the only difference being the color scheme. How would I go about displaying different drawables based on the version?
For example, let's say I have a Blue version and a Red version. I would like to use the same source code for both but have an easy way to convert between the two color schemes. I am confused on how I would tell Android that I want to use the Blue version (or Red) and have it access files perhaps in resources/drawables/Blue or resources/drawables/Red. I found the link below, but I don't understand how I can implement this using just one package. Is it possible?
Dynamically change the name of the resource file to be used?
Making resources theme dependent

One way to do it is simply have a SharedPreferences int, where if it is 0, the app is in "red mode" and 1, it is in "blue mode". The downside of this is that you have to change the scheme in each activity.

Related

How to identify that asset added inside Assets.xcassets are used in project?

How to identify quick way the Assets added inside Assets.xcassets for Images & color are using inside project or not.
Example:
int value = 10
In this case int value not used inside application which give an warning.
Initialization of immutable value 'value' was never used; consider replacing with assignment to '_' or removing it
What if inside Assets.xcassets added color or image are not used how to identify ?
Xcode has no tool which could highlight not used assets but there is a open source project called "AssetsChecker" which will do the job.
There's no way a tool can know which assets are not being used by your application.
Imagine that you are creating a Weather app, and the data you receive from the server includes the image_key that you use to know which asset to load.
If a tool to find unused assets was used, it would tell you that every image or color that is not referenced directly is not used, which would yield a LOT of false positives.

How do I modify a library in flutter?

I'm using a library that draws barcodes and under them it drows the barcode number, however it draws text just in black color. I found the code that chooses the color during this operations, however when I try to change this code library from Colors.black to Colors.white and I save it, it doesn't save for some reason. So I suppose there is a different way to modify code from library, but I don't know how.
#Gabriel, You can easily copy .dart files from the package/library you're using to your project and modify the code to your liking. For e.g. if you are using https://pub.dev/packages/toggle_switch, then you can access the source code from the GitHub location of the package in pub.dev and download it from GitHub,
You can then copy .dart files from <project>/lib to your <project>/lib and modify them accordingly. Make sure you add reference in the source code to credit the original developers and add their GitHub link.
Good luck!

How to check if any apps are associated with file extension

I want to make "Open in.." function in my iOS application.
Is there any way to check if any app on this device is associated with file extension that i want to share?
If there are no apps on current device to open file with such an extension than UIDocumentInteractionController will not be displayed after clicking on "Open in.." button, but i want not to show this button in such case.
So the question is: how to check if any app on device can open some file with specific extension?
Update:
For example UIDocumentInteractionController has NSArray property icons.
It contains images of all aplications that can open the file with my extension. But if there are no applications it contans image of empty application.
So i can't check it using docInteractionController.icons.count == 0 for example. I am looking for other tricks.'
Thanks, in advance.
Although UIDocumentInteractionController does not offer a way to discover in advance whether there are any applications that can handle a document, -presentOpenInMenuFromRect: will return a flag indicating whether there were any applications that could open a document. This requires you to have already set up and presented the controller, which is not optimal.
There is a workaround for this, a little hacky but is functional: Before you invoke the "real" interaction controller, create a dummy one using a dummy document, and present it from the rect of the window's bounds. This guarantees that it will "appear" offscreen, so your user won't see it. At that point, you have the flag returned from -present, and you can immediately dismiss the dummy controller, and the proceed to show your UI appropriately.
On OSX, you can get a list of application bundle identifiers capable of handling a specific content type using LSCopyAllRoleHandlersForContentType. But on iOS, I don't think there is such a way.
If I find, I'll edit my answer.
Considering you are looking for other tricks, you can check if that one image in the icons array is the generic document icon.
If it is then you know that there is no app associated to handle that file type. But this approach will be OS version dependent as generic file icon may change.
From the official documentation:
To declare its support for file types, your app must include the
CFBundleDocumentTypes key in its Info.plistproperty list file. (See
“Core Foundation Keys”.) The system adds this information to a
registry that other apps can access through a document interaction
controller.
To me this indicates that the registry can only be accessed through UIDocumentInteractionController and so no, you would not be able to know in advance if there are any available apps for the file format (which would be totally in line with Apple's philosophy of not letting apps interact directly with each other).
UPDATE:
as you said the icons property contains an image even with no applications present. I checked and all the other methods and properties of the controller do not give an hint about the apps that may open the current file format.
You said in case that no app can open the specified file format there is an "image of empty application". Maybe you can extract that icon and when the array icons only has one image check if the extracted image and the icon are the same?

One App, Multiple Branding

I have made an application for the iPhone but it is required to be released with multiple brandings. Eg Differernt:
App Name
Icons
Default.png
Text replaced for the app name in IB
Colour schemes for all images such as backgrounds, icons etc
I'm not sure of the best way to do this.
I was thinking of a plist file for each branding that would have the name of the files to load eg "brand1_background.png" for brand1 but that would get very messy with the text replacement. It would also mean that all brands images would be in the package making it of larger size.
Looking around a bit I could have an 'images' folder for each brand and drag it in to build that brand's app, however the text is still an issue.
I'm wondering how everyone else would handle this situation as I want to do it as right as possible.
There are 2 different aspects to this problem, which I'd describe as follows:
Stuff that can be changed dynamically
Stuff that can't be changed dynamically
The first category is super easy. If you have your colo(u)r schemes stored in some easily-readable format like a plist or whatever, you can just load up that file during app startup, and build UIColor objects from them and use those where appropriate. The same goes for images used within the app itself. This is not a hard problem.
The second category is trickier. This is stuff that has to be baked into the application because of code signing. This means that the things like the App Name, the icon, Default.png, etc, all have to be changed before the app is signed in the compilation process. So what I'd do is bake up a bunch of scripts to take your branding information (name, image files, icons, etc) and load it up, then generate your Info.plist file and whatnot. This should be done as one of the first phases of your compilation.
For what it's worth, I work on an application where we do exactly this process, and it works pretty well. It's a bit tedious to update when we change what resources get branded, but I'm not sure there's any decent way around that.
Create a target for each of your brandings. For each single target you can add different files (e.g. images) and set an app name. You can even use the same file names (but stored under a different location) and you can build your brand-apps pretty fast.

Eclipse standard warning/error overlay icons

I'm writing an Eclipse plug-in... In my custom label decorator, I want to overlay a warning icon, and I'd like to use the standard one used by eclipse (the little yellow triangle). How can I get an image descriptor of this icon?
I tried using
workbench.getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING)
since that ID seems to match what I'm looking for, but the shared images collection doesn't actually have that image in it (so I just get a null returned).
Is there some other shared image collection that I should be looking at?
You have run across an Eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=304397
The bugzilla entry gives this code as workaround:
ImageDescriptor descriptor =
JFaceResources.getImageRegistry().getDescriptor("org.eclipse.jface.fieldassist.IMG_DEC_FIELD_WARNING");