Skip to content

Instantly share code, notes, and snippets.

@nitishparkar
Created December 3, 2014 06:51
Show Gist options
  • Save nitishparkar/d797aab56e3ad52ea741 to your computer and use it in GitHub Desktop.
Save nitishparkar/d797aab56e3ad52ea741 to your computer and use it in GitHub Desktop.
A ruby script to copy icons to appropriate directories in android app
require "fileutils"
ICONS_DIR = "path-to-icons-dir" # Ex. "/home/nitish/Downloads/material-design-icons-1.0.0/"
PROJECT_RES_DIR = "path-to-res-dir-of-android-app" # Ex. "/home/nitish/Projects/android_app/app/src/main/res/"
DRAWABLES = ["drawable-hdpi", "drawable-mdpi", "drawable-xhdpi", "drawable-xxhdpi"]
COLORS = {
"grey" => "grey600",
"gray" => "grey600",
"black" => "black",
"white" => "white"
}
def add_icon(category_name, icon_name, color)
DRAWABLES.each do |drawable|
FileUtils.cp(ICONS_DIR + category_name + "/" + drawable + "/" + "ic_#{icon_name}_#{color}_24dp.png", PROJECT_RES_DIR + drawable + "/", verbose: true)
end
end
def delete_icon(icon_name, color)
DRAWABLES.each do |drawable|
FileUtils.rm(PROJECT_RES_DIR + drawable + "/" + "ic_#{icon_name}_#{color}_24dp.png", verbose: true)
end
end
puts "Enter Category"
category_name = gets.chomp
puts "Enter Icon Name"
icon_name = gets.chomp
puts 'Enter Color: ["grey" (default), "black", "white"] '
color = COLORS[gets.chomp] || "grey600"
puts 'Enter "1" for Adding Icon (default) or "2" for Removing'
choice = gets.chomp
if choice == "2"
delete_icon(icon_name, color)
else
add_icon(category_name, icon_name, color)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment