app-info 2.6.5 → 2.7.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: Resources.proto
3
+
4
+ require 'google/protobuf'
5
+ require 'app_info/protobuf/models/Configuration_pb'
6
+
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_file("Resources.proto", :syntax => :proto3) do
9
+ add_message "aapt.pb.StringPool" do
10
+ optional :data, :bytes, 1
11
+ end
12
+ add_message "aapt.pb.SourcePosition" do
13
+ optional :line_number, :uint32, 1
14
+ optional :column_number, :uint32, 2
15
+ end
16
+ add_message "aapt.pb.Source" do
17
+ optional :path_idx, :uint32, 1
18
+ optional :position, :message, 2, "aapt.pb.SourcePosition"
19
+ end
20
+ add_message "aapt.pb.ToolFingerprint" do
21
+ optional :tool, :string, 1
22
+ optional :version, :string, 2
23
+ end
24
+ add_message "aapt.pb.ResourceTable" do
25
+ optional :source_pool, :message, 1, "aapt.pb.StringPool"
26
+ repeated :package, :message, 2, "aapt.pb.Package"
27
+ repeated :overlayable, :message, 3, "aapt.pb.Overlayable"
28
+ repeated :tool_fingerprint, :message, 4, "aapt.pb.ToolFingerprint"
29
+ end
30
+ add_message "aapt.pb.PackageId" do
31
+ optional :id, :uint32, 1
32
+ end
33
+ add_message "aapt.pb.Package" do
34
+ optional :package_id, :message, 1, "aapt.pb.PackageId"
35
+ optional :package_name, :string, 2
36
+ repeated :type, :message, 3, "aapt.pb.Type"
37
+ end
38
+ add_message "aapt.pb.TypeId" do
39
+ optional :id, :uint32, 1
40
+ end
41
+ add_message "aapt.pb.Type" do
42
+ optional :type_id, :message, 1, "aapt.pb.TypeId"
43
+ optional :name, :string, 2
44
+ repeated :entry, :message, 3, "aapt.pb.Entry"
45
+ end
46
+ add_message "aapt.pb.Visibility" do
47
+ optional :level, :enum, 1, "aapt.pb.Visibility.Level"
48
+ optional :source, :message, 2, "aapt.pb.Source"
49
+ optional :comment, :string, 3
50
+ end
51
+ add_enum "aapt.pb.Visibility.Level" do
52
+ value :UNKNOWN, 0
53
+ value :PRIVATE, 1
54
+ value :PUBLIC, 2
55
+ end
56
+ add_message "aapt.pb.AllowNew" do
57
+ optional :source, :message, 1, "aapt.pb.Source"
58
+ optional :comment, :string, 2
59
+ end
60
+ add_message "aapt.pb.Overlayable" do
61
+ optional :name, :string, 1
62
+ optional :source, :message, 2, "aapt.pb.Source"
63
+ optional :actor, :string, 3
64
+ end
65
+ add_message "aapt.pb.OverlayableItem" do
66
+ optional :source, :message, 1, "aapt.pb.Source"
67
+ optional :comment, :string, 2
68
+ repeated :policy, :enum, 3, "aapt.pb.OverlayableItem.Policy"
69
+ optional :overlayable_idx, :uint32, 4
70
+ end
71
+ add_enum "aapt.pb.OverlayableItem.Policy" do
72
+ value :NONE, 0
73
+ value :PUBLIC, 1
74
+ value :SYSTEM, 2
75
+ value :VENDOR, 3
76
+ value :PRODUCT, 4
77
+ value :SIGNATURE, 5
78
+ value :ODM, 6
79
+ value :OEM, 7
80
+ value :ACTOR, 8
81
+ value :CONFIG_SIGNATURE, 9
82
+ end
83
+ add_message "aapt.pb.EntryId" do
84
+ optional :id, :uint32, 1
85
+ end
86
+ add_message "aapt.pb.Entry" do
87
+ optional :entry_id, :message, 1, "aapt.pb.EntryId"
88
+ optional :name, :string, 2
89
+ optional :visibility, :message, 3, "aapt.pb.Visibility"
90
+ optional :allow_new, :message, 4, "aapt.pb.AllowNew"
91
+ optional :overlayable_item, :message, 5, "aapt.pb.OverlayableItem"
92
+ repeated :config_value, :message, 6, "aapt.pb.ConfigValue"
93
+ end
94
+ add_message "aapt.pb.ConfigValue" do
95
+ optional :config, :message, 1, "aapt.pb.Configuration"
96
+ optional :value, :message, 2, "aapt.pb.Value"
97
+ end
98
+ add_message "aapt.pb.Value" do
99
+ optional :source, :message, 1, "aapt.pb.Source"
100
+ optional :comment, :string, 2
101
+ optional :weak, :bool, 3
102
+ oneof :value do
103
+ optional :item, :message, 4, "aapt.pb.Item"
104
+ optional :compound_value, :message, 5, "aapt.pb.CompoundValue"
105
+ end
106
+ end
107
+ add_message "aapt.pb.Item" do
108
+ oneof :value do
109
+ optional :ref, :message, 1, "aapt.pb.Reference"
110
+ optional :str, :message, 2, "aapt.pb.String"
111
+ optional :raw_str, :message, 3, "aapt.pb.RawString"
112
+ optional :styled_str, :message, 4, "aapt.pb.StyledString"
113
+ optional :file, :message, 5, "aapt.pb.FileReference"
114
+ optional :id, :message, 6, "aapt.pb.Id"
115
+ optional :prim, :message, 7, "aapt.pb.Primitive"
116
+ end
117
+ end
118
+ add_message "aapt.pb.CompoundValue" do
119
+ oneof :value do
120
+ optional :attr, :message, 1, "aapt.pb.Attribute"
121
+ optional :style, :message, 2, "aapt.pb.Style"
122
+ optional :styleable, :message, 3, "aapt.pb.Styleable"
123
+ optional :array, :message, 4, "aapt.pb.Array"
124
+ optional :plural, :message, 5, "aapt.pb.Plural"
125
+ end
126
+ end
127
+ add_message "aapt.pb.Boolean" do
128
+ optional :value, :bool, 1
129
+ end
130
+ add_message "aapt.pb.Reference" do
131
+ optional :type, :enum, 1, "aapt.pb.Reference.Type"
132
+ optional :id, :uint32, 2
133
+ optional :name, :string, 3
134
+ optional :private, :bool, 4
135
+ optional :is_dynamic, :message, 5, "aapt.pb.Boolean"
136
+ end
137
+ add_enum "aapt.pb.Reference.Type" do
138
+ value :REFERENCE, 0
139
+ value :ATTRIBUTE, 1
140
+ end
141
+ add_message "aapt.pb.Id" do
142
+ end
143
+ add_message "aapt.pb.String" do
144
+ optional :value, :string, 1
145
+ end
146
+ add_message "aapt.pb.RawString" do
147
+ optional :value, :string, 1
148
+ end
149
+ add_message "aapt.pb.StyledString" do
150
+ optional :value, :string, 1
151
+ repeated :span, :message, 2, "aapt.pb.StyledString.Span"
152
+ end
153
+ add_message "aapt.pb.StyledString.Span" do
154
+ optional :tag, :string, 1
155
+ optional :first_char, :uint32, 2
156
+ optional :last_char, :uint32, 3
157
+ end
158
+ add_message "aapt.pb.FileReference" do
159
+ optional :path, :string, 1
160
+ optional :type, :enum, 2, "aapt.pb.FileReference.Type"
161
+ end
162
+ add_enum "aapt.pb.FileReference.Type" do
163
+ value :UNKNOWN, 0
164
+ value :PNG, 1
165
+ value :BINARY_XML, 2
166
+ value :PROTO_XML, 3
167
+ end
168
+ add_message "aapt.pb.Primitive" do
169
+ oneof :oneof_value do
170
+ optional :null_value, :message, 1, "aapt.pb.Primitive.NullType"
171
+ optional :empty_value, :message, 2, "aapt.pb.Primitive.EmptyType"
172
+ optional :float_value, :float, 3
173
+ optional :dimension_value, :uint32, 13
174
+ optional :fraction_value, :uint32, 14
175
+ optional :int_decimal_value, :int32, 6
176
+ optional :int_hexadecimal_value, :uint32, 7
177
+ optional :boolean_value, :bool, 8
178
+ optional :color_argb8_value, :uint32, 9
179
+ optional :color_rgb8_value, :uint32, 10
180
+ optional :color_argb4_value, :uint32, 11
181
+ optional :color_rgb4_value, :uint32, 12
182
+ optional :dimension_value_deprecated, :float, 4
183
+ optional :fraction_value_deprecated, :float, 5
184
+ end
185
+ end
186
+ add_message "aapt.pb.Primitive.NullType" do
187
+ end
188
+ add_message "aapt.pb.Primitive.EmptyType" do
189
+ end
190
+ add_message "aapt.pb.Attribute" do
191
+ optional :format_flags, :uint32, 1
192
+ optional :min_int, :int32, 2
193
+ optional :max_int, :int32, 3
194
+ repeated :symbol, :message, 4, "aapt.pb.Attribute.Symbol"
195
+ end
196
+ add_message "aapt.pb.Attribute.Symbol" do
197
+ optional :source, :message, 1, "aapt.pb.Source"
198
+ optional :comment, :string, 2
199
+ optional :name, :message, 3, "aapt.pb.Reference"
200
+ optional :value, :uint32, 4
201
+ optional :type, :uint32, 5
202
+ end
203
+ add_enum "aapt.pb.Attribute.FormatFlags" do
204
+ value :NONE, 0
205
+ value :ANY, 65535
206
+ value :REFERENCE, 1
207
+ value :STRING, 2
208
+ value :INTEGER, 4
209
+ value :BOOLEAN, 8
210
+ value :COLOR, 16
211
+ value :FLOAT, 32
212
+ value :DIMENSION, 64
213
+ value :FRACTION, 128
214
+ value :ENUM, 65536
215
+ value :FLAGS, 131072
216
+ end
217
+ add_message "aapt.pb.Style" do
218
+ optional :parent, :message, 1, "aapt.pb.Reference"
219
+ optional :parent_source, :message, 2, "aapt.pb.Source"
220
+ repeated :entry, :message, 3, "aapt.pb.Style.Entry"
221
+ end
222
+ add_message "aapt.pb.Style.Entry" do
223
+ optional :source, :message, 1, "aapt.pb.Source"
224
+ optional :comment, :string, 2
225
+ optional :key, :message, 3, "aapt.pb.Reference"
226
+ optional :item, :message, 4, "aapt.pb.Item"
227
+ end
228
+ add_message "aapt.pb.Styleable" do
229
+ repeated :entry, :message, 1, "aapt.pb.Styleable.Entry"
230
+ end
231
+ add_message "aapt.pb.Styleable.Entry" do
232
+ optional :source, :message, 1, "aapt.pb.Source"
233
+ optional :comment, :string, 2
234
+ optional :attr, :message, 3, "aapt.pb.Reference"
235
+ end
236
+ add_message "aapt.pb.Array" do
237
+ repeated :element, :message, 1, "aapt.pb.Array.Element"
238
+ end
239
+ add_message "aapt.pb.Array.Element" do
240
+ optional :source, :message, 1, "aapt.pb.Source"
241
+ optional :comment, :string, 2
242
+ optional :item, :message, 3, "aapt.pb.Item"
243
+ end
244
+ add_message "aapt.pb.Plural" do
245
+ repeated :entry, :message, 1, "aapt.pb.Plural.Entry"
246
+ end
247
+ add_message "aapt.pb.Plural.Entry" do
248
+ optional :source, :message, 1, "aapt.pb.Source"
249
+ optional :comment, :string, 2
250
+ optional :arity, :enum, 3, "aapt.pb.Plural.Arity"
251
+ optional :item, :message, 4, "aapt.pb.Item"
252
+ end
253
+ add_enum "aapt.pb.Plural.Arity" do
254
+ value :ZERO, 0
255
+ value :ONE, 1
256
+ value :TWO, 2
257
+ value :FEW, 3
258
+ value :MANY, 4
259
+ value :OTHER, 5
260
+ end
261
+ add_message "aapt.pb.XmlNode" do
262
+ optional :source, :message, 3, "aapt.pb.SourcePosition"
263
+ oneof :node do
264
+ optional :element, :message, 1, "aapt.pb.XmlElement"
265
+ optional :text, :string, 2
266
+ end
267
+ end
268
+ add_message "aapt.pb.XmlElement" do
269
+ repeated :namespace_declaration, :message, 1, "aapt.pb.XmlNamespace"
270
+ optional :namespace_uri, :string, 2
271
+ optional :name, :string, 3
272
+ repeated :attribute, :message, 4, "aapt.pb.XmlAttribute"
273
+ repeated :child, :message, 5, "aapt.pb.XmlNode"
274
+ end
275
+ add_message "aapt.pb.XmlNamespace" do
276
+ optional :prefix, :string, 1
277
+ optional :uri, :string, 2
278
+ optional :source, :message, 3, "aapt.pb.SourcePosition"
279
+ end
280
+ add_message "aapt.pb.XmlAttribute" do
281
+ optional :namespace_uri, :string, 1
282
+ optional :name, :string, 2
283
+ optional :value, :string, 3
284
+ optional :source, :message, 4, "aapt.pb.SourcePosition"
285
+ optional :resource_id, :uint32, 5
286
+ optional :compiled_item, :message, 6, "aapt.pb.Item"
287
+ end
288
+ end
289
+ end
290
+
291
+ module Aapt
292
+ module Pb
293
+ StringPool = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.StringPool").msgclass
294
+ SourcePosition = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.SourcePosition").msgclass
295
+ Source = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Source").msgclass
296
+ ToolFingerprint = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.ToolFingerprint").msgclass
297
+ ResourceTable = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.ResourceTable").msgclass
298
+ PackageId = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.PackageId").msgclass
299
+ Package = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Package").msgclass
300
+ TypeId = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.TypeId").msgclass
301
+ Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Type").msgclass
302
+ Visibility = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Visibility").msgclass
303
+ Visibility::Level = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Visibility.Level").enummodule
304
+ AllowNew = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.AllowNew").msgclass
305
+ Overlayable = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Overlayable").msgclass
306
+ OverlayableItem = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.OverlayableItem").msgclass
307
+ OverlayableItem::Policy = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.OverlayableItem.Policy").enummodule
308
+ EntryId = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.EntryId").msgclass
309
+ Entry = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Entry").msgclass
310
+ ConfigValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.ConfigValue").msgclass
311
+ Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Value").msgclass
312
+ Item = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Item").msgclass
313
+ CompoundValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.CompoundValue").msgclass
314
+ Boolean = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Boolean").msgclass
315
+ Reference = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Reference").msgclass
316
+ Reference::Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Reference.Type").enummodule
317
+ Id = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Id").msgclass
318
+ String = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.String").msgclass
319
+ RawString = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.RawString").msgclass
320
+ StyledString = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.StyledString").msgclass
321
+ StyledString::Span = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.StyledString.Span").msgclass
322
+ FileReference = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.FileReference").msgclass
323
+ FileReference::Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.FileReference.Type").enummodule
324
+ Primitive = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Primitive").msgclass
325
+ Primitive::NullType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Primitive.NullType").msgclass
326
+ Primitive::EmptyType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Primitive.EmptyType").msgclass
327
+ Attribute = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Attribute").msgclass
328
+ Attribute::Symbol = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Attribute.Symbol").msgclass
329
+ Attribute::FormatFlags = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Attribute.FormatFlags").enummodule
330
+ Style = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Style").msgclass
331
+ Style::Entry = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Style.Entry").msgclass
332
+ Styleable = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Styleable").msgclass
333
+ Styleable::Entry = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Styleable.Entry").msgclass
334
+ Array = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Array").msgclass
335
+ Array::Element = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Array.Element").msgclass
336
+ Plural = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Plural").msgclass
337
+ Plural::Entry = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Plural.Entry").msgclass
338
+ Plural::Arity = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.Plural.Arity").enummodule
339
+ XmlNode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.XmlNode").msgclass
340
+ XmlElement = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.XmlElement").msgclass
341
+ XmlNamespace = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.XmlNamespace").msgclass
342
+ XmlAttribute = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("aapt.pb.XmlAttribute").msgclass
343
+ end
344
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'app_info/protobuf/models/Resources_pb'
4
+ require 'app_info/core_ext'
5
+ require 'forwardable'
6
+
7
+ module AppInfo
8
+ module Protobuf
9
+ class Resources
10
+ def self.parse(io)
11
+ doc = Aapt::Pb::ResourceTable.decode(io)
12
+ new(doc)
13
+ end
14
+
15
+ include Helper::ReferenceParser
16
+
17
+ attr_reader :packages, :tool_fingerprint
18
+
19
+ def initialize(doc)
20
+ parse(doc)
21
+ end
22
+
23
+ def find(reference, locale: '')
24
+ type, name = reference_segments(reference)
25
+ packages.each do |_, package|
26
+ next unless value = package.find(name, type: type, locale: locale)
27
+
28
+ return value
29
+ end
30
+
31
+ nil
32
+ end
33
+
34
+ def first_package
35
+ packages.values[0]
36
+ end
37
+
38
+ private
39
+
40
+ def parse(doc)
41
+ define_packages(doc)
42
+ define_tool_fingerprint(doc)
43
+ end
44
+
45
+ def define_packages(doc)
46
+ @packages = doc.package.each_with_object({}) do |package, obj|
47
+ obj[package.package_name] = Resources::Package.new(package)
48
+ end
49
+ end
50
+
51
+ def define_tool_fingerprint(doc)
52
+ @tool_fingerprint = doc.tool_fingerprint
53
+ end
54
+
55
+ class Package
56
+ include Helper::Defines
57
+
58
+ attr_reader :name, :types
59
+
60
+ def initialize(doc)
61
+ @name = doc.package_name
62
+ define_types(doc)
63
+ end
64
+
65
+ def find(name, type: nil, locale: '')
66
+ match_types(type).each do |type_name|
67
+ next unless respond_to?(type_name.to_sym)
68
+ next unless entries = send(type_name.to_sym).entries
69
+
70
+ entries.each do |entry|
71
+ return entry.value(locale: locale) if entry.name == name
72
+ end
73
+ end
74
+
75
+ nil
76
+ end
77
+
78
+ def entries(type)
79
+ method_name = type.to_sym
80
+ return unless respond_to?(method_name)
81
+
82
+ send(method_name)
83
+ end
84
+
85
+ private
86
+
87
+ BUILDIN_PREFIX = 'android:'
88
+
89
+ def match_types(type)
90
+ return types if type.to_s.empty?
91
+ return type if type.is_a?(Array)
92
+
93
+ type = type[BUILDIN_PREFIX.size..-1] if type.start_with?(BUILDIN_PREFIX)
94
+ if types.include?(type)
95
+ [type]
96
+ else
97
+ []
98
+ end
99
+ end
100
+
101
+ def define_types(doc)
102
+ @types = []
103
+ doc.type.each do |type|
104
+ type_name = type.name
105
+ entry = Entry.parse_from(type, self)
106
+ @types << type_name
107
+
108
+ define_instance_method(type_name, entry)
109
+ end
110
+
111
+ @types
112
+ end
113
+ end
114
+
115
+ class Entry
116
+ def self.parse_from(type, package)
117
+ type.entry.each_with_object([]) do |entry, obj|
118
+ obj << Entry.new(entry, package)
119
+ end
120
+ end
121
+
122
+ include Helper::Defines
123
+
124
+ attr_reader :name, :values
125
+
126
+ def initialize(doc, package)
127
+ @package = package
128
+ @name = doc.name
129
+ parse(doc)
130
+ end
131
+
132
+ def value(locale: '')
133
+ values = @values.select { |v| v.locale == locale }
134
+ return first_value if values.empty?
135
+
136
+ values.size == 1 ? values[0] : values
137
+ end
138
+
139
+ def first_value
140
+ @first_value ||= @values[0]
141
+ end
142
+
143
+ def locales
144
+ @locales ||= @values.map(&:locale)
145
+ end
146
+
147
+ private
148
+
149
+ def parse(doc)
150
+ @values = doc.config_value.each_with_object([]) do |config_value, obj|
151
+ value = Value.new(config_value, @package)
152
+ obj << value
153
+ end
154
+ end
155
+ end
156
+
157
+ class Value
158
+ include Helper::ReferenceParser
159
+ extend Forwardable
160
+
161
+ attr_reader :locale, :config, :original_value, :value, :type
162
+
163
+ def initialize(doc, package)
164
+ @package = package
165
+ @config = doc.config
166
+ @value = parsed_value(doc.value)
167
+ end
168
+
169
+ def_delegators :config, :locale
170
+
171
+ def layout_size
172
+ @config.screen_layout_size
173
+ end
174
+
175
+ def night_mode?
176
+ @config.ui_mode_night == :UI_MODE_NIGHT_NIGHT
177
+ end
178
+
179
+ def inspect
180
+ "<#{self.class.name} value:#{@value} original_value:#{original_value}>"
181
+ end
182
+
183
+ def to_h
184
+ @config.to_h.merge(value: @original_value.to_h)
185
+ end
186
+
187
+ private
188
+
189
+ def parsed_value(doc)
190
+ value_from = doc.send(doc.value.to_sym)
191
+ type_value = value_from.send(value_from.value.to_sym)
192
+ @original_value = type_value
193
+
194
+ case type_value
195
+ when Aapt::Pb::Reference
196
+ type, name = reference_segments(type_value.name)
197
+ @package.find(name, type: type)
198
+ when Aapt::Pb::String, Aapt::Pb::RawString
199
+ @type = :string
200
+ type_value.value
201
+ when Aapt::Pb::FileReference
202
+ @type = :file
203
+ type_value.path
204
+ when Aapt::Pb::Primitive
205
+ parsed_prim_value(type_value)
206
+ else
207
+ type_value
208
+ end
209
+ end
210
+
211
+ def parsed_prim_value(value)
212
+ @type = value.oneof_value.to_sym
213
+ real_value = value.send(@type)
214
+
215
+ case @type
216
+ when :color_rgb8_value, :color_argb8_value
217
+ "##{real_value.to_s(16).upcase}"
218
+ when :null_value
219
+ nil
220
+ when :empty_value
221
+ ''
222
+ else
223
+ real_value
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppInfo
4
- VERSION = '2.6.5'
4
+ VERSION = '2.7.0.beta1'
5
5
  end