mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 06:14:25 +02:00
Merge pull request #28 from revanced/additional-bag-methods
Additional bag methods
This commit is contained in:
commit
6cba5d1d7f
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.arsc.value.plurals;
|
package com.reandroid.arsc.value.plurals;
|
||||||
|
|
||||||
|
import com.reandroid.arsc.value.ResConfig;
|
||||||
import com.reandroid.arsc.value.ResValueMap;
|
import com.reandroid.arsc.value.ResValueMap;
|
||||||
import com.reandroid.arsc.value.ValueType;
|
import com.reandroid.arsc.value.ValueType;
|
||||||
import com.reandroid.arsc.value.bag.MapBag;
|
import com.reandroid.arsc.value.bag.MapBag;
|
||||||
@ -50,12 +51,15 @@
|
|||||||
return PluralsQuantity.valueOf(valueMap);
|
return PluralsQuantity.valueOf(valueMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQuantityString(PluralsQuantity quantity) {
|
public String getQuantityString(PluralsQuantity quantity, ResConfig resConfig) {
|
||||||
PluralsBagItem item = get(quantity);
|
PluralsBagItem item = get(quantity);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return item.getQualityString();
|
return item.getQualityString(resConfig);
|
||||||
|
}
|
||||||
|
public String getQuantityString(PluralsQuantity quantity) {
|
||||||
|
return getQuantityString(quantity, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuantityString(PluralsQuantity quantity, String str) {
|
public void setQuantityString(PluralsQuantity quantity, String str) {
|
||||||
|
@ -15,12 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.arsc.value.plurals;
|
package com.reandroid.arsc.value.plurals;
|
||||||
|
|
||||||
|
import com.reandroid.arsc.chunk.TableBlock;
|
||||||
import com.reandroid.arsc.item.StringItem;
|
import com.reandroid.arsc.item.StringItem;
|
||||||
import com.reandroid.arsc.item.TableString;
|
import com.reandroid.arsc.item.TableString;
|
||||||
import com.reandroid.arsc.value.ResValueMap;
|
import com.reandroid.arsc.value.*;
|
||||||
import com.reandroid.arsc.value.ValueType;
|
|
||||||
import com.reandroid.arsc.value.bag.BagItem;
|
import com.reandroid.arsc.value.bag.BagItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PluralsBagItem extends BagItem {
|
public class PluralsBagItem extends BagItem {
|
||||||
private PluralsBagItem(ResValueMap bagItem) {
|
private PluralsBagItem(ResValueMap bagItem) {
|
||||||
super(bagItem);
|
super(bagItem);
|
||||||
@ -41,17 +43,49 @@
|
|||||||
return PluralsQuantity.valueOf(mBagItem);
|
return PluralsQuantity.valueOf(mBagItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQualityString() {
|
public String getQualityString(ResConfig resConfig) {
|
||||||
switch (getValueType()) {
|
switch (getValueType()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
return getStringValue();
|
return getStringValue();
|
||||||
case REFERENCE:
|
case REFERENCE:
|
||||||
// TODO: resolve string reference based on language
|
Entry entry = null;
|
||||||
|
if (mBagItem != null) {
|
||||||
|
entry = mBagItem.getEntry();
|
||||||
|
}
|
||||||
|
if (entry == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resConfig == null) {
|
||||||
|
resConfig = entry.getResConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry stringRes = null;
|
||||||
|
if (resConfig != null) {
|
||||||
|
TableBlock tableBlock = entry.getPackageBlock().getTableBlock();
|
||||||
|
List<Entry> resolvedList = tableBlock.resolveReferenceWithConfig(getValue(), resConfig);
|
||||||
|
if (resolvedList.size() > 0) {
|
||||||
|
stringRes = resolvedList.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stringRes == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ResValue resValue = stringRes.getResValue();
|
||||||
|
if (resValue == null || resValue.getValueType() != ValueType.STRING) {
|
||||||
|
throw new IllegalArgumentException("Not a STR reference: " + formattedRefValue());
|
||||||
|
}
|
||||||
|
return resValue.getValueAsString();
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Not STR/REFERENCE ValueType=" + getValueType());
|
throw new IllegalArgumentException("Not STR/REFERENCE ValueType=" + getValueType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String formattedRefValue() {
|
||||||
|
return String.format("@0x%08x", getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -61,7 +95,7 @@
|
|||||||
if (hasStringValue()) {
|
if (hasStringValue()) {
|
||||||
builder.append(getStringValue());
|
builder.append(getStringValue());
|
||||||
} else {
|
} else {
|
||||||
builder.append(String.format("@0x%08x", getValue()));
|
builder.append(formattedRefValue());
|
||||||
}
|
}
|
||||||
builder.append("</item>");
|
builder.append("</item>");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
@ -40,6 +40,9 @@
|
|||||||
public int getParentId() {
|
public int getParentId() {
|
||||||
return getTableEntry().getParentId();
|
return getTableEntry().getParentId();
|
||||||
}
|
}
|
||||||
|
public void setParentId(int id) {
|
||||||
|
getTableEntry().setParentId(id);
|
||||||
|
}
|
||||||
|
|
||||||
public int getResourceId() {
|
public int getResourceId() {
|
||||||
com.reandroid.arsc.value.Entry entry = getEntry();
|
com.reandroid.arsc.value.Entry entry = getEntry();
|
||||||
|
@ -18,10 +18,13 @@
|
|||||||
import com.reandroid.arsc.decoder.ValueDecoder;
|
import com.reandroid.arsc.decoder.ValueDecoder;
|
||||||
import com.reandroid.arsc.item.StringItem;
|
import com.reandroid.arsc.item.StringItem;
|
||||||
import com.reandroid.arsc.item.TableString;
|
import com.reandroid.arsc.item.TableString;
|
||||||
|
import com.reandroid.arsc.value.attribute.AttributeBag;
|
||||||
|
import com.reandroid.arsc.value.attribute.AttributeBagItem;
|
||||||
import com.reandroid.arsc.value.bag.BagItem;
|
import com.reandroid.arsc.value.bag.BagItem;
|
||||||
import com.reandroid.arsc.value.Entry;
|
import com.reandroid.arsc.value.Entry;
|
||||||
import com.reandroid.arsc.value.ResValueMap;
|
import com.reandroid.arsc.value.ResValueMap;
|
||||||
import com.reandroid.arsc.value.ValueType;
|
import com.reandroid.arsc.value.ValueType;
|
||||||
|
import com.reandroid.common.EntryStore;
|
||||||
|
|
||||||
public class StyleBagItem extends BagItem {
|
public class StyleBagItem extends BagItem {
|
||||||
private StyleBagItem(ResValueMap bagItem) {
|
private StyleBagItem(ResValueMap bagItem) {
|
||||||
@ -47,6 +50,12 @@
|
|||||||
char prefix = 0;
|
char prefix = 0;
|
||||||
return block.buildResourceName(mBagItem.getName(), prefix, false);
|
return block.buildResourceName(mBagItem.getName(), prefix, false);
|
||||||
}
|
}
|
||||||
|
public Entry getAttributeEntry(EntryStore entryStore) {
|
||||||
|
if (mBagItem == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return entryStore.getEntryGroup(mBagItem.getName()).pickOne();
|
||||||
|
}
|
||||||
|
|
||||||
public int getNameId() {
|
public int getNameId() {
|
||||||
if (mBagItem == null) {
|
if (mBagItem == null) {
|
||||||
@ -58,6 +67,10 @@
|
|||||||
public boolean hasAttributeValue() {
|
public boolean hasAttributeValue() {
|
||||||
return getValueType() == ValueType.ATTRIBUTE;
|
return getValueType() == ValueType.ATTRIBUTE;
|
||||||
}
|
}
|
||||||
|
public boolean hasIntValue() {
|
||||||
|
ValueType valueType = getValueType();
|
||||||
|
return valueType == ValueType.INT_DEC || valueType == ValueType.INT_HEX;
|
||||||
|
}
|
||||||
|
|
||||||
public String getValueAsReference() {
|
public String getValueAsReference() {
|
||||||
ValueType valueType = getValueType();
|
ValueType valueType = getValueType();
|
||||||
@ -77,6 +90,18 @@
|
|||||||
int id = getValue();
|
int id = getValue();
|
||||||
return entry.buildResourceName(id, prefix, includeType);
|
return entry.buildResourceName(id, prefix, includeType);
|
||||||
}
|
}
|
||||||
|
public String decodeAttributeValue(AttributeBag attr, EntryStore entryStore) {
|
||||||
|
if (!hasIntValue()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return attr.decodeAttributeValue(entryStore, getValue());
|
||||||
|
}
|
||||||
|
public AttributeBagItem[] getFlagsOrEnum(AttributeBag attr) {
|
||||||
|
if (!hasIntValue()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return attr.searchValue(getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@ -158,4 +183,7 @@
|
|||||||
public static StyleBagItem createFloat(float n) {
|
public static StyleBagItem createFloat(float n) {
|
||||||
return new StyleBagItem(ValueType.FLOAT, Float.floatToIntBits(n));
|
return new StyleBagItem(ValueType.FLOAT, Float.floatToIntBits(n));
|
||||||
}
|
}
|
||||||
|
public static StyleBagItem enumOrFlag(AttributeBag attr, String valueString) {
|
||||||
|
return encoded(attr.encodeEnumOrFlagValue(valueString));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user