Class: Android::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/android/resource.rb

Overview

based on Android OS source code /frameworks/base/include/utils/ResourceTypes.h

Defined Under Namespace

Classes: Chunk, ChunkHeader, ResStringPool, ResTableConfig, ResTableEntry, ResTableHeader, ResTableLibraryType, ResTableMap, ResTableMapEntry, ResTablePackage, ResTableType, ResTableTypeSpec, ResValue, UnknownChunkType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Resource

Returns a new instance of Resource.



604
605
606
607
608
609
# File 'lib/android/resource.rb', line 604

def initialize(data)
  data.force_encoding(Encoding::ASCII_8BIT)
  @data = data

  parse
end

Instance Attribute Details

#packagesObject (readonly)

Returns the value of attribute packages.



602
603
604
# File 'lib/android/resource.rb', line 602

def packages
  @packages
end

Instance Method Details

#find(rsc_id, opt = {}) ⇒ Object

Note:

This method only support string resource for now.

Note:

Always return nil if assign not string type res id.

This method only support string resource for now. find resource by resource id

Parameters:

  • res_id (String)

    (like ‘@0x7f010001’ or ‘@string/key’)

  • opts (Hash)

    option

Raises:

  • (ArgumentError)

    invalid id format

Since:

  • 0.5.0



633
634
635
# File 'lib/android/resource.rb', line 633

def find(rsc_id, opt={})
  first_pkg.find(rsc_id, opt)
end

#first_pkgObject



659
660
661
# File 'lib/android/resource.rb', line 659

def first_pkg
  @packages.first[1]
end

#localesArray<String>

Return resources locales

Returns:

  • (Array<String>)

    all strings of locales.

Since:

  • 2.7.0



655
656
657
# File 'lib/android/resource.rb', line 655

def locales
  first_pkg.locales
end

#package_countFixnum

Returns number of packages.

Returns:

  • (Fixnum)

    number of packages



617
618
619
# File 'lib/android/resource.rb', line 617

def package_count
  @res_table.package_count
end

#res_hex_id(readable_id) ⇒ String

convert readable resource id to hex id

Parameters:

  • readable_id (String)

    readable resource id (‘@string/key’)

Returns:

  • (String)

    hexoctet format resource id(‘@0x7f010001’)

Since:

  • 0.5.0



648
649
650
# File 'lib/android/resource.rb', line 648

def res_hex_id(readable_id)
  first_pkg.res_hex_id(readable_id)
end

#res_readable_id(hex_id) ⇒ String

Returns readable resource id (‘@string/key’).

Parameters:

  • hex_id (String)

    hexoctet format resource id(‘@0x7f010001’)

Returns:

  • (String)

    readable resource id (‘@string/key’)

Since:

  • 0.5.0



640
641
642
# File 'lib/android/resource.rb', line 640

def res_readable_id(hex_id)
  first_pkg.res_readable_id(hex_id)
end

#stringsArray<String>

Returns all strings defined in arsc.

Returns:

  • (Array<String>)

    all strings defined in arsc.



612
613
614
# File 'lib/android/resource.rb', line 612

def strings
  @string_pool.strings
end