The code is pretty straightforward. Taking XHDPI as the scale (1.0), I've used factors for conversion of every screen in accordance with this official link: https://developer.android.com/guide/practices/screens_support.html
Feel free to edit the factors at your own needs. Here's how to use the code:
- Run it in any java IDE
- Specify the location of the project in the console when asked (There might be some file I/O exceptions, and in that case, you can manually enter the full location of the file in the code)
- Specify which dimension you want as output
- Copy and paste the output in your required dimens.xml file
NOTE: This is my first code for community. Pardon if it's too naive.