/* * 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.item.IntegerArray; import com.reandroid.arsc.item.IntegerItem; import com.reandroid.arsc.item.StringItem; import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONArray; import com.reandroid.json.JSONObject; import java.util.AbstractList; import java.util.ArrayList; import java.util.List; public abstract class StringArray extends OffsetBlockArray implements JSONConvert { private boolean mUtf8; public StringArray(IntegerArray offsets, IntegerItem itemCount, IntegerItem itemStart, boolean is_utf8) { super(offsets, itemCount, itemStart); this.mUtf8=is_utf8; setEndBytes((byte)0x00); } public List toStringList(){ return new AbstractList() { @Override public String get(int i) { T item=StringArray.this.get(i); if(item==null){ return null; } return item.getHtml(); } @Override public int size() { return childesCount(); } }; } public List removeUnusedStrings(){ List allUnused=listUnusedStrings(); remove(allUnused); return allUnused; } public List listUnusedStrings(){ List results=new ArrayList<>(); for(T item:listItems()){ if(!item.hasReference()){ results.add(item); } } return results; } public void setUtf8(boolean is_utf8){ if(mUtf8==is_utf8){ return; } mUtf8=is_utf8; T[] childes=getChildes(); if(childes!=null){ int max=childes.length; for(int i=0;i