Skip to content

Instantly share code, notes, and snippets.

@mdumrauf
Last active September 26, 2016 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdumrauf/4b4a42feb71bbdd5bb23 to your computer and use it in GitHub Desktop.
Save mdumrauf/4b4a42feb71bbdd5bb23 to your computer and use it in GitHub Desktop.
Script to change dimens.xml sizes
# 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