
com.reandroid.arsc.array.ResXmlIDArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ARSCLib Show documentation
Show all versions of ARSCLib Show documentation
Android binary resources read/write library
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.array;
import com.reandroid.arsc.base.BlockArray;
import com.reandroid.arsc.header.HeaderBlock;
import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.ResXmlID;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ResXmlIDArray extends BlockArray {
private final HeaderBlock mHeaderBlock;
private final Map mResIdMap;
private boolean mUpdated;
public ResXmlIDArray(HeaderBlock headerBlock){
super();
this.mHeaderBlock=headerBlock;
this.mResIdMap=new HashMap<>();
}
public void addResourceId(int index, int resId){
if(index<0){
return;
}
ensureSize(index+1);
ResXmlID xmlID=get(index);
if(xmlID!=null){
xmlID.set(resId);
}
}
public ResXmlID getOrCreate(int resId){
updateIdMap();
ResXmlID xmlID=mResIdMap.get(resId);
if(xmlID!=null){
return xmlID;
}
xmlID=new ResXmlID(resId);
add(xmlID);
mUpdated=true;
mResIdMap.put(resId, xmlID);
return xmlID;
}
public ResXmlID getByResId(int resId){
updateIdMap();
return mResIdMap.get(resId);
}
public void refreshIdMap(){
mUpdated = false;
updateIdMap();
}
private void updateIdMap(){
if(mUpdated){
return;
}
mUpdated=true;
mResIdMap.clear();
ResXmlID[] allChildes=getChildes();
if(allChildes==null||allChildes.length==0){
return;
}
int max=allChildes.length;
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy