Last active
September 26, 2016 08:19
-
-
Save mdumrauf/4b4a42feb71bbdd5bb23 to your computer and use it in GitHub Desktop.
Script to change dimens.xml sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Factor to apply to all dimens | |
factor = 2 | |
text = File.open('dimens.xml').read | |
resized = File.open('dimens-resized.xml', 'w') | |
text.gsub!(/\r\n?/, "\n") | |
resized.write "<resources>\n" | |
text.each_line do |line| | |
if !line.start_with? ("<!--") | |
splitted = line.split(">") | |
if !splitted.nil? | |
splitted2 = splitted[1] | |
if !splitted2.nil? && splitted2.strip.size > 0 | |
dimens_array = splitted2.split("<") | |
number = dimens_array[0] | |
the_number = 0 | |
if (number.match (/^[\d]+$/)).nil? && !number.start_with?("@") | |
# Apply factor | |
the_number = number.gsub(/dp|sp/, "") | |
unit = number.end_with?("dp") ? "dp" : "sp" | |
resized.write "#{splitted[0]}>#{the_number.to_i/factor}#{unit}</dimen>\n" | |
else | |
resized.write "#{splitted[0]}>#{number}</dimen>\n" | |
end | |
end | |
end | |
else | |
resized.write line | |
end | |
end | |
resized.write "</resources>\n" | |
resized.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment