Three flavor dimensions, want to cover two - android

My Android app has three flavor dimensions. Let's call them Color, Size, and Shape. So I have (Blue|Red)(Small|Large)(Round|Square).
Is it possible to have a source folder for blueSmall that covers both blueSmallRound and blueSmallSquare? If I go straight ahead and create blueSmall under src, Android Studio doesn't see it.
I want to place a manifest there, not Java sources, so having a library with just Color and Size as dimensions is not an option.

Related

How to create a circular icon for my Android app?

I just swapped my android launcher icon(just learned how). I noticed MANY icons on my android are circular and I am wondering do I have to get an image done like that OR is there way I can have the launcher put the icon(a png with transparent background) and draw a circle for the launcher somehow? (this would be easier that fooling around in some drawing tool as well).
In the app I used CircleImageView for contacts which did the circle but that was in java, and android launcher is xml so not sure if I can use CircleImageView?
You'll need to use adaptive icons instead of a single image to allow Android to adjust your icon. Essentially this is defining a background drawable and a foreground drawable, and Android will do the rest.
If you right click your res/drawable folder in Android Studio, then select New -> Image Asset, you will see the following wizard. This will let you easily create launcher icons that work in all shapes.
For further information you may find the official Android docs helpful, as well as Nick Butcher's excellent guide.

How to automatically change drawables depending on a flavor?

I'm working on a really messy app and first time with flavors. App has like 4,5 flavors all with identical background colors, drawables, etc. Only logo is different.
Now I have to make a new flavor with completely different layout. Background color should be yellow instead of grey and drawable images should be black instead of white. The problem is, I have like 100 different white images. Is there a way I can change them to black automatically? (designer can redraw them or whatever to be black and I can put them in drawable folder of that flavor) Or I would have to programmatically check if new flavor is used then call setDrawable(newBlackImage) on every widget that uses white drawable? That seems like a very complicated way to do since all drawables are set via XML layout..
The way they've been using flavors was creating resource bool file and then check in code if some key has value true/false then hide/show some things... So I assume I should do something similar with this, or no?
This is what the project structure for one of my flavors looks like:
As you can see, every flavor only has different launcher and login screen icons. Also each has their own arrays, bools and strings resource files. But all of them share same layout resources and drawables with white icons.
I think you're already in the right way. By creating specific flavours for each group of drawable in your gradle file you'll just need to create a drawable folder for the flavours with specific files.
For example, the flavour 'black' will need a drawable folder in which all your black-background images will be stored.
In order to get it working, all resources must exist for all flavours so you won't need to change any part of your code.
You can find a quick guide here:
https://medium.com/#thiagolopessilva/the-handling-multiple-java-source-and-resources-using-flavors-on-gradle-18a4b581285b

App Icon on Device is too small

My problem is that the App Icon on my device looks way too small in comparison to the other apps. I read some solution on other questions, like this one Android App Icon size too small but this doesn't seems to be my problem. In the Android Studio you can make a right click on "res" where you can find new --> image asset where you can create such a icon. it creates icons for all the different sizes like mdpi, hdpi and so on. So i thougt that i might display the app icon correctly but it doesn't. can anybody help me?
In "Configure Image Asset", click "Legacy", change "Shape" from "Square" to "None", and the image padding will appear. Go back to "Foreground Layer" and resize the image to fill the padding.
Try to use this. Its very useful, fast and free. And thats what I use.
If your icon already has a shape, remember to set the shape to none. Hope it helps!
If you are getting the same results, I also recommend this website, where I usually get "bigger" icons.
I found the launcher icons generator puts there a small padding, that is the reason for smaller icons. On the other way it is recommended by Google team here.
Android expects product icons to be provided at 48dp, with edges at 1dp.
All is on you to decide. In case the icon applies to whole square space - use padding, otherwise when small object is not square shape, rather fit to edges :)
I had the same issue. I fixed it like so:
Create the adaptive icon through Android Asset Studio. In the third tab you can select "Create Legacy Icon". Only this legacy one is going to be too small! The others will be fine.
So the thing I did was just to replace the icon_launcher.png files (this is the legacy icon).
If you use any single image directly as android:icon="#drawable/ic_launcher"
It'll be shown correctly on old devices but on android 26+ it'll appear small
Use this approach to make the icon appear like fitXY scaleType for imageview, that is, it's corners can be clipped like cardview but it will not be shrinked
Step 1
Delete ic_launcher from drawables and paste it in mipmap-xxhdpi-v4
Add transparent padding of width/6 px to your launcher icon online
Step 2
Paste the second file as ic_launcher_foreground
Step 3
Create ic_launcher.xml under res/mipmap-anydpi-v26 and add this content
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="#mipmap/ic_launcher_foreground" />
<background android:drawable="#color/colorTransparent"/>
</adaptive-icon>
Step 4
Edit the manifest and use mipmap instead of drawable
Now your icon should not appear shrinked/zoomed
This is useful when your app icon can't be split into foreground/background eg some graphic image as app icon
How it works:
For API26+ devices, mipmap-anydpi-v26 will take precedence over mipmap-xxhdpi-v4 and system will load icon from xml, which in turn, loads foreground from ic_launcher_foreground, automatically crop 2/3 of its size because it's 'adaptive icon'. (This is the reason we add padding of width/6 from all sides
For older devices the ic_launcher.webp will be used directly
Tested on API 21-31

What's the proper way to scale/size background images for Android?

I want to have an image cover the background of my Android game, but I'm new to Android development - are there conventions for what file type such an image should be?
What is a conventional size?
What's the proper way to scale/refit this image to different devices (right now I just added the imageresource to the back layout, but this scales the image and distorts it)?
I'm planning on using photoshop and drawing out the image there, is there a more recommended method?
Thanks
"Are there conventions for what file type such an image should be?" The image can be any common file format. PNG is common, probably because it's loss-less and supports transparency, but I don't know the details.
"What is a conventional size?" You will have to produce an image of various resolutions to support all the screens on which your game may be used. You can create new directories in your project tree that look like res/drawable-{screen-type}, where {screen-type} is a screen size/resolution/minimum dimension. For details on how this works see Supporting Multiple Screens.
"What's the proper way to scale/refit this image to different devices?" See #2. To avoid distorting your image, you will need to produce different sized/resolution images to fit various screen sizes.
With regards to Photoshop -- if you are producing a background with a complex design/graphic, you will probably want to use the graphics editor you know best, such as Photoshop. However, if you are making a background that will just be a simple pattern that repeats, or even just a solid, consider making just a small bit of the image, and then using an Android Shape Drawable or Nine Patch Drawable to tile/repeat/stretch your image. This will reduce the number of different-sized images you need to produce for different screens, and will also reduce the space your app takes up, since you will have fewer resources to package. For info on the Drawable resources that Android supports, see Drawable Resources.
The background drawable is stretched by default. If you want to change that, you can create an XML <bitmap> drawable resource referencing your image and set its gravity attribute to something different than fill.
The result can be better if your image is decomposed in different smaller images aligned properly. For exemple, a main background color, a top part and a bottom part. You can then combine the different layers with a Layer list drawable or using a custom layout.

Different states of one image

I am making an app for Andorid. There are 2 restrictions:
It must be light (2-3MB)
I need to have minimal graphic files (not having a file in diffrent state and option)
How to make the layout so I can modify only the red dots (image or code) for each option that is selected?
Making 6 different states of this image is not a good answer (too big data)
Make this image as two layered. One for your main button, and other for red dots(They should be PNG's and 6 of them for different dots).And place these PNG above your main button according to the choice(Make them visible/invisible). Do you have its PSD file btw?

Categories

Resources