mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 06:14:25 +02:00
Code cleaning
This commit is contained in:
parent
34150065e7
commit
2e29f7a7bb
@ -11,10 +11,7 @@ import com.reandroid.lib.json.JSONArray;
|
|||||||
import com.reandroid.lib.json.JSONObject;
|
import com.reandroid.lib.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
||||||
implements Comparator<ResXmlAttribute>, JSONConvert<JSONArray> {
|
implements Comparator<ResXmlAttribute>, JSONConvert<JSONArray> {
|
||||||
@ -27,14 +24,7 @@ public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
|||||||
this.mAttributeCount=attributeCount;
|
this.mAttributeCount=attributeCount;
|
||||||
}
|
}
|
||||||
public void sortAttributes(){
|
public void sortAttributes(){
|
||||||
Collection<ResXmlAttribute> items = listItems();
|
sort(this);
|
||||||
if(items.size()<2){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<ResXmlAttribute> elementList = new ArrayList<>(items);
|
|
||||||
elementList.sort(this);
|
|
||||||
clearChildes();
|
|
||||||
addAll(elementList.toArray(new ResXmlAttribute[0]));
|
|
||||||
}
|
}
|
||||||
private void refreshCount(){
|
private void refreshCount(){
|
||||||
short count= (short) childesCount();
|
short count= (short) childesCount();
|
||||||
@ -76,6 +66,7 @@ public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONArray toJson() {
|
public JSONArray toJson() {
|
||||||
|
sortAttributes();
|
||||||
JSONArray jsonArray=new JSONArray();
|
JSONArray jsonArray=new JSONArray();
|
||||||
int i=0;
|
int i=0;
|
||||||
for(ResXmlAttribute attr:listItems()){
|
for(ResXmlAttribute attr:listItems()){
|
||||||
|
@ -66,7 +66,6 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
|||||||
}
|
}
|
||||||
elementData=newInstance(0);
|
elementData=newInstance(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(T[] blocks){
|
public void addAll(T[] blocks){
|
||||||
if(blocks==null||blocks.length==0){
|
if(blocks==null||blocks.length==0){
|
||||||
return;
|
return;
|
||||||
@ -98,6 +97,16 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
|||||||
trimNullBlocks();
|
trimNullBlocks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void sort(Comparator<T> comparator){
|
||||||
|
T[] data=this.elementData;
|
||||||
|
if(comparator==null || data==null || data.length<2){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Arrays.sort(data, 0, data.length, comparator);
|
||||||
|
for(int i=0;i<data.length;i++){
|
||||||
|
data[i].setIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
public void setItem(int index, T item){
|
public void setItem(int index, T item){
|
||||||
ensureSize(index+1);
|
ensureSize(index+1);
|
||||||
elementData[index]=item;
|
elementData[index]=item;
|
||||||
@ -283,7 +292,6 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
|||||||
item.setParent(this);
|
item.setParent(this);
|
||||||
}
|
}
|
||||||
elementData=update;
|
elementData=update;
|
||||||
Arrays.fill(old, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -293,7 +301,7 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
|||||||
|
|
||||||
private class BlockIterator implements Iterator<T> {
|
private class BlockIterator implements Iterator<T> {
|
||||||
private int mCursor;
|
private int mCursor;
|
||||||
private int mMaxSize;
|
private final int mMaxSize;
|
||||||
private final boolean mSkipNullBlock;
|
private final boolean mSkipNullBlock;
|
||||||
BlockIterator(boolean skipNullBlock){
|
BlockIterator(boolean skipNullBlock){
|
||||||
mSkipNullBlock=skipNullBlock;
|
mSkipNullBlock=skipNullBlock;
|
||||||
|
@ -302,7 +302,6 @@ public class ResXmlAttribute extends FixedBlockContainer
|
|||||||
setRawValue(val);
|
setRawValue(val);
|
||||||
setValueStringReference(-1);
|
setValueStringReference(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCompareName(){
|
private String getCompareName(){
|
||||||
int id=getNameResourceID();
|
int id=getNameResourceID();
|
||||||
StringBuilder builder=new StringBuilder();
|
StringBuilder builder=new StringBuilder();
|
||||||
@ -317,7 +316,26 @@ public class ResXmlAttribute extends FixedBlockContainer
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ResXmlAttribute other) {
|
public int compareTo(ResXmlAttribute other) {
|
||||||
return getCompareName().compareTo(other.getCompareName());
|
int id1=getNameResourceID();
|
||||||
|
int id2=other.getNameResourceID();
|
||||||
|
if(id1==0 && id2!=0){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(id2==0 && id1!=0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(id1!=0){
|
||||||
|
return Integer.compare(id1, id2);
|
||||||
|
}
|
||||||
|
String name1=getName();
|
||||||
|
if(name1==null){
|
||||||
|
name1="";
|
||||||
|
}
|
||||||
|
String name2=other.getName();
|
||||||
|
if(name2==null){
|
||||||
|
name2="";
|
||||||
|
}
|
||||||
|
return name1.compareTo(name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,11 +2,8 @@ package com.reandroid.lib.arsc.chunk.xml;
|
|||||||
|
|
||||||
import com.reandroid.lib.arsc.chunk.ChunkType;
|
import com.reandroid.lib.arsc.chunk.ChunkType;
|
||||||
import com.reandroid.lib.arsc.array.ResXmlAttributeArray;
|
import com.reandroid.lib.arsc.array.ResXmlAttributeArray;
|
||||||
import com.reandroid.lib.arsc.io.BlockReader;
|
|
||||||
import com.reandroid.lib.arsc.item.ShortItem;
|
import com.reandroid.lib.arsc.item.ShortItem;
|
||||||
import com.reandroid.lib.arsc.pool.ResXmlStringPool;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
||||||
@ -37,18 +34,6 @@ public class ResXmlStartElement extends BaseXmlChunk {
|
|||||||
addChild(mAttributeArray);
|
addChild(mAttributeArray);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onReadBytes(BlockReader reader) throws IOException {
|
|
||||||
super.onReadBytes(reader);
|
|
||||||
if(mClassAttributePosition.get()==0 && mStyleAttributePosition.get()==0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ResXmlStringPool stringPool=getStringPool();
|
|
||||||
int c=(mClassAttributePosition.get() & 0xffff)-1;
|
|
||||||
int style = (mStyleAttributePosition.get() >>> 16) - 1;
|
|
||||||
int z=c+style;
|
|
||||||
stringPool.childesCount();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPreRefreshRefresh(){
|
protected void onPreRefreshRefresh(){
|
||||||
sortAttributes();
|
sortAttributes();
|
||||||
}
|
}
|
||||||
@ -66,24 +51,22 @@ public class ResXmlStartElement extends BaseXmlChunk {
|
|||||||
if(classAttribute!=null){
|
if(classAttribute!=null){
|
||||||
mClassAttributePosition.set((short) (classAttribute.getIndex()+1));
|
mClassAttributePosition.set((short) (classAttribute.getIndex()+1));
|
||||||
// In case obfuscation
|
// In case obfuscation
|
||||||
if(!"class".equals(classAttribute.getName())){
|
if(!ATTRIBUTE_NAME_CLASS.equals(classAttribute.getName())){
|
||||||
classAttribute.setName("class", 0);
|
classAttribute.setName(ATTRIBUTE_NAME_CLASS, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(styleAttribute!=null){
|
if(styleAttribute!=null){
|
||||||
mStyleAttributePosition.set((short) (styleAttribute.getIndex()+1));
|
mStyleAttributePosition.set((short) (styleAttribute.getIndex()+1));
|
||||||
// In case obfuscation
|
// In case obfuscation
|
||||||
if(!"style".equals(styleAttribute.getName())){
|
if(!ATTRIBUTE_NAME_STYLE.equals(styleAttribute.getName())){
|
||||||
styleAttribute.setName("style", 0);
|
styleAttribute.setName(ATTRIBUTE_NAME_STYLE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void calculatePositions(){
|
void calculatePositions(){
|
||||||
|
ResXmlAttribute idAttribute=getAttribute(ATTRIBUTE_RESOURCE_ID_id);
|
||||||
int android_id=0x010100d0;
|
ResXmlAttribute classAttribute=getNoIdAttribute(ATTRIBUTE_NAME_CLASS);
|
||||||
ResXmlAttribute idAttribute=getAttribute(android_id);
|
ResXmlAttribute styleAttribute=getNoIdAttribute(ATTRIBUTE_NAME_STYLE);
|
||||||
ResXmlAttribute classAttribute=getNoIdAttribute("class");
|
|
||||||
ResXmlAttribute styleAttribute=getNoIdAttribute("style");
|
|
||||||
|
|
||||||
if(idAttribute!=null){
|
if(idAttribute!=null){
|
||||||
mIdAttributePosition.set((short) (idAttribute.getIndex()+1));
|
mIdAttributePosition.set((short) (idAttribute.getIndex()+1));
|
||||||
@ -244,4 +227,17 @@ public class ResXmlStartElement extends BaseXmlChunk {
|
|||||||
|
|
||||||
private static final short ATTRIBUTES_UNIT_SIZE=0x0014;
|
private static final short ATTRIBUTES_UNIT_SIZE=0x0014;
|
||||||
private static final short ATTRIBUTES_DEFAULT_START=0x0014;
|
private static final short ATTRIBUTES_DEFAULT_START=0x0014;
|
||||||
|
/*
|
||||||
|
* Find another way to mark an attribute is class, device actually relies on
|
||||||
|
* value of mClassAttributePosition */
|
||||||
|
private static final String ATTRIBUTE_NAME_CLASS="class";
|
||||||
|
/*
|
||||||
|
* Find another way to mark an attribute is style, device actually relies on
|
||||||
|
* value of mStyleAttributePosition */
|
||||||
|
private static final String ATTRIBUTE_NAME_STYLE="style";
|
||||||
|
/*
|
||||||
|
* Resource id value of attribute 'android:id'
|
||||||
|
* instead of relying on hardcoded value, we should find another way to
|
||||||
|
* mark an attribute is 'id' */
|
||||||
|
private static final int ATTRIBUTE_RESOURCE_ID_id =0x010100d0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user