class Android::Resource
based on Android
OS source code /frameworks/base/include/utils/ResourceTypes.h @see justanapplication.wordpress.com/category/android/android-resources/
Attributes
@returns [Hash] { name(String) => value(ResTablePackage
) }
Public Class Methods
# File lib/android/resource.rb, line 449 def initialize(data) data.force_encoding(Encoding::ASCII_8BIT) @data = data parse() end
Public Instance Methods
This method only support string resource for now.
find resource by resource id @param [String] res_id (like ‘@0x7f010001’ or ‘@string/key’) @param [Hash] opts option @option opts [String] :lang language code like ‘ja’, ‘cn’… @option opts [String] :contry cantry code like ‘jp’… @raise [ArgumentError] invalid id format @note
This method only support string resource for now.
@note
Always return nil if assign not string type res id.
@since 0.5.0
# File lib/android/resource.rb, line 478 def find(rsc_id, opt={}) first_pkg.find(rsc_id, opt) end
# File lib/android/resource.rb, line 497 def first_pkg @packages.first[1] end
@return [Fixnum] number of packages
# File lib/android/resource.rb, line 462 def package_count @res_table.package_count end
convert readable resource id to hex id @param [String] readable_id readable resource id (‘@string/key’) @return [String] hexoctet format resource id(‘@0x7f010001’) @since 0.5.0
# File lib/android/resource.rb, line 493 def res_hex_id(readable_id) first_pkg.res_hex_id(readable_id) end
@param [String] hex_id hexoctet format resource id(‘@0x7f010001’) @return [String] readable resource id (‘@string/key’) @since 0.5.0
# File lib/android/resource.rb, line 485 def res_readable_id(hex_id) first_pkg.res_readable_id(hex_id) end
@return [Array<String>] all strings defined in arsc.
# File lib/android/resource.rb, line 457 def strings @string_pool.strings end
Private Instance Methods
# File lib/android/resource.rb, line 501 def parse offset = 0 while offset < @data.size type = @data[offset, 2].unpack('v')[0] #print "[%#08x] " % offset @packages = {} case type when 0x0001 # RES_STRING_POOL_TYPE @string_pool = ResStringPool.new(@data, offset) offset += @string_pool.size #puts "RES_STRING_POOL_TYPE %#x, %#x" % [@string_pool.size, offset] when 0x0002 # RES_TABLE_TYPE #puts "RES_TABLE_TYPE" @res_table = ResTableHeader.new(@data, offset) offset += @res_table.header_size when 0x0200 # RES_TABLE_PACKAGE_TYPE #puts "RES_TABLE_PACKAGE_TYPE" pkg = ResTablePackage.new(@data, offset) pkg.global_string_pool = @string_pool offset += pkg.size @packages[pkg.name] = pkg else raise "chunk type error: type:%#04x" % type end end end