You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
replace arsc_parser with ARSClib
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
|
||||
package android.content.res;
|
||||
|
||||
import com.hq.arscresourcesparser.ArscResourcesParser;
|
||||
import com.reandroid.arsc.chunk.TableBlock;
|
||||
import com.reandroid.arsc.value.ResValueMap;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
@@ -27,6 +28,7 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.os.Trace;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import java.util.ArrayList;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -85,7 +87,7 @@ public final class AssetManager {
|
||||
private boolean mOpen = true;
|
||||
private HashMap<Integer, RuntimeException> mRefStacks;
|
||||
|
||||
private ArscResourcesParser arsc_parser;
|
||||
private TableBlock tableBlock;
|
||||
|
||||
/**
|
||||
* Create a new AssetManager containing only the basic system assets.
|
||||
@@ -95,8 +97,13 @@ public final class AssetManager {
|
||||
* {@hide}
|
||||
*/
|
||||
public AssetManager() {
|
||||
// NOTE: this enforces a particular order when specifying the MicroG .apk in classpath
|
||||
arsc_parser = new ArscResourcesParser(ClassLoader.getSystemClassLoader().getResource("resources.arsc"));
|
||||
try {
|
||||
// NOTE: this enforces a particular order when specifying the MicroG .apk in classpath
|
||||
InputStream inFile = ClassLoader.getSystemClassLoader().getResourceAsStream("resources.arsc");
|
||||
tableBlock = TableBlock.load(inFile);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "failed to load resources.arsc" + e);
|
||||
}
|
||||
|
||||
// FIXME: evaluate if this can be axed
|
||||
synchronized (this) {
|
||||
@@ -160,7 +167,7 @@ public final class AssetManager {
|
||||
* identifier for the current configuration / skin.
|
||||
*/
|
||||
/*package*/ final CharSequence getResourceText(int id) {
|
||||
return arsc_parser.getResource(id);
|
||||
return tableBlock.search(id).pickOne().getResValue().getDataAsPoolString().get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +194,11 @@ public final class AssetManager {
|
||||
* @param id Resource id of the string array
|
||||
*/
|
||||
/*package*/ final String[] getResourceStringArray(final int id) {
|
||||
return arsc_parser.getResourceArray(id);
|
||||
ArrayList<String> values = new ArrayList<String>();
|
||||
for(ResValueMap map : tableBlock.search(id).pickOne().getResValueMapArray().getChildes()) {
|
||||
values.add(map.getValueAsString());
|
||||
}
|
||||
return values.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -687,34 +698,7 @@ public final class AssetManager {
|
||||
/*package*/ /*native*/ final int getResourceIdentifier(String name, String type, String defPackage) {
|
||||
System.out.println("getResourceIdentifier("+name+","+type+","+defPackage+") called");
|
||||
|
||||
int typeId;
|
||||
|
||||
if(type.equals("color")) {
|
||||
typeId = 1;
|
||||
}else if(type.equals("drawable")) {
|
||||
typeId = 2;
|
||||
}else if(type.equals("layout")) {
|
||||
typeId = 3;
|
||||
}else if(type.equals("dimen")) {
|
||||
typeId = 4;
|
||||
}else if(type.equals("string")) {
|
||||
typeId = 5;
|
||||
}else if(type.equals("array")) {
|
||||
typeId = 6;
|
||||
}else if(type.equals("style")) {
|
||||
typeId = 7;
|
||||
}else if(type.equals("menu")) {
|
||||
typeId = 8;
|
||||
}else if(type.equals("id")) {
|
||||
typeId = 9;
|
||||
} else {
|
||||
System.out.println("returning 0 (no such type: >"+type+"<)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
System.out.println("returning: " + arsc_parser.getResourceId(name, typeId));
|
||||
System.out.println("debug: " + arsc_parser.getResource(0x7f020002));
|
||||
return arsc_parser.getResourceId(name, typeId);
|
||||
return tableBlock.pickOne().getEntry("", type, name).getResourceId();
|
||||
}
|
||||
|
||||
/*package*/ native final String getResourceName(int resid);
|
||||
|
||||
Reference in New Issue
Block a user