diff --git a/src/main/java/com/reandroid/arsc/value/ResConfig.java b/src/main/java/com/reandroid/arsc/value/ResConfig.java index 563f509..21712ec 100755 --- a/src/main/java/com/reandroid/arsc/value/ResConfig.java +++ b/src/main/java/com/reandroid/arsc/value/ResConfig.java @@ -13,1482 +13,1481 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.reandroid.arsc.value; + package com.reandroid.arsc.value; -import com.reandroid.arsc.base.Block; -import com.reandroid.arsc.container.FixedBlockContainer; -import com.reandroid.arsc.io.BlockLoad; -import com.reandroid.arsc.io.BlockReader; -import com.reandroid.arsc.item.ByteArray; -import com.reandroid.arsc.item.IntegerItem; -import com.reandroid.json.JSONConvert; -import com.reandroid.json.JSONObject; + import com.reandroid.arsc.base.Block; + import com.reandroid.arsc.container.FixedBlockContainer; + import com.reandroid.arsc.io.BlockLoad; + import com.reandroid.arsc.io.BlockReader; + import com.reandroid.arsc.item.ByteArray; + import com.reandroid.arsc.item.IntegerItem; + import com.reandroid.json.JSONConvert; + import com.reandroid.json.JSONObject; -import java.io.IOException; -import java.util.Arrays; + import java.io.IOException; + import java.util.Arrays; public class ResConfig extends FixedBlockContainer - implements BlockLoad, JSONConvert, Comparable { + implements BlockLoad, JSONConvert, Comparable { - private final IntegerItem configSize; - private final ByteArray mValuesContainer; + private final IntegerItem configSize; + private final ByteArray mValuesContainer; - private String mQualifiers; - private int mQualifiersStamp; + private String mQualifiers; + private int mQualifiersStamp; - public ResConfig(){ - super(2); - this.configSize = new IntegerItem(SIZE_64); - this.mValuesContainer = new ByteArray(SIZE_64 - 4); - addChild(0, configSize); - addChild(1, mValuesContainer); - this.configSize.setBlockLoad(this); - this.mQualifiersStamp = 0; - } - public void copyFrom(ResConfig resConfig){ - if(resConfig==this||resConfig==null){ - return; - } - setConfigSize(resConfig.getConfigSize()); - mValuesContainer.putByteArray(0, resConfig.mValuesContainer.toArray()); - } - @Override - public void onBlockLoaded(BlockReader reader, Block sender) throws IOException { - if(sender==configSize){ - setConfigSize(configSize.get()); - } - } - @Override - protected void onPreRefreshRefresh(){ - int count=countBytes(); - configSize.set(count); - } - @Override - protected void onRefreshed() { - } - public void parseQualifiers(String name){ - ResConfigHelper.parseQualifiers(this, name); - } - public void setConfigSize(int size){ - if(!isValidSize(size)){ - throw new IllegalArgumentException("Invalid config size = " + size); - } - this.configSize.set(size); - size=size-4; - mValuesContainer.setSize(size); - } - public int getConfigSize(){ - return this.configSize.get(); - } - public boolean trimToSize(int size){ - int current=getConfigSize(); - if(current==size){ - return true; - } - if(!isValidSize(size)){ - return false; - } - if(current> 5) + ((in0 & 0x03) << 3)); - byte third = (byte) ((in0 & 0x7c) >> 2); + private static char[] unPackLanguage(byte in0, byte in1) { + return unpackLanguageOrRegion(in0, in1, 'a'); + } + private static char[] unPackRegion(byte in0, byte in1) { + return unpackLanguageOrRegion(in0, in1, '0'); + } + private static char[] unpackLanguageOrRegion(byte in0, byte in1, char base) { + char[] out; + if ((in0 & 0x80) !=0) { + out = new char[3]; + byte first = (byte) (in1 & 0x1f); + byte second = (byte) (((in1 & 0xe0) >> 5) + ((in0 & 0x03) << 3)); + byte third = (byte) ((in0 & 0x7c) >> 2); - out[0] = (char) (first + base); - out[1] = (char) (second + base); - out[2] = (char) (third + base); - }else if (in0 != 0) { - out = new char[2]; - out[0] = (char) in0; - out[1] = (char) in1; - }else { - out = new char[2]; - } - return out; - } - private static byte[] packLanguage(char[] language) { - return packLanguageOrRegion(language, 'a'); - } - private static byte[] packRegion(char[] region) { - return packLanguageOrRegion(region, '0'); - } - private static byte[] packLanguageOrRegion(char[] in, char base) { - byte[] out = new byte[2]; - if(in==null || in.length<2){ - return out; - } - if (in.length==2 || in[2] == 0 || in[2] == '-') { - out[0] = (byte) in[0]; - out[1] = (byte) in[1]; - } else { - byte first = (byte) ((in[0] - base) & 0x007f); - byte second = (byte) ((in[1] - base) & 0x007f); - byte third = (byte) ((in[2] - base) & 0x007f); + out[0] = (char) (first + base); + out[1] = (char) (second + base); + out[2] = (char) (third + base); + }else if (in0 != 0) { + out = new char[2]; + out[0] = (char) in0; + out[1] = (char) in1; + }else { + out = new char[2]; + } + return out; + } + private static byte[] packLanguage(char[] language) { + return packLanguageOrRegion(language, 'a'); + } + private static byte[] packRegion(char[] region) { + return packLanguageOrRegion(region, '0'); + } + private static byte[] packLanguageOrRegion(char[] in, char base) { + byte[] out = new byte[2]; + if(in==null || in.length<2){ + return out; + } + if (in.length==2 || in[2] == 0 || in[2] == '-') { + out[0] = (byte) in[0]; + out[1] = (byte) in[1]; + } else { + byte first = (byte) ((in[0] - base) & 0x007f); + byte second = (byte) ((in[1] - base) & 0x007f); + byte third = (byte) ((in[2] - base) & 0x007f); - out[0] = (byte) (0x80 | (third << 2) | (second >> 3)); - out[1] = (byte) ((second << 5) | first); - } - return out; - } + out[0] = (byte) (0x80 | (third << 2) | (second >> 3)); + out[1] = (byte) ((second << 5) | first); + } + return out; + } - private static byte[] toByteArray(char[] chs, int len){ - byte[] bts=new byte[len]; - if(chs==null){ - return bts; - } - int sz=chs.length; - for(int i=0; i= min){ - return str; - } - StringBuilder builder = new StringBuilder(); - builder.append(str); - int remain = min - length; - for(int i=0; i0 && str.charAt(index) == postfix){ - str = str.substring(0, index); - length = str.length(); - index = length - 1; - } - return str; - } - public static boolean isValidSize(int size){ - switch (size){ - case SIZE_16: - case SIZE_28: - case SIZE_32: - case SIZE_36: - case SIZE_48: - case SIZE_52: - case SIZE_56: - case SIZE_64: - return true; - default: - return size > SIZE_64; - } - } + private static byte[] toByteArray(char[] chs, int len){ + byte[] bts=new byte[len]; + if(chs==null){ + return bts; + } + int sz=chs.length; + for(int i=0; i= min){ + return str; + } + StringBuilder builder = new StringBuilder(); + builder.append(str); + int remain = min - length; + for(int i=0; i0 && str.charAt(index) == postfix){ + str = str.substring(0, index); + length = str.length(); + index = length - 1; + } + return str; + } + public static boolean isValidSize(int size){ + switch (size){ + case SIZE_16: + case SIZE_28: + case SIZE_32: + case SIZE_36: + case SIZE_48: + case SIZE_52: + case SIZE_56: + case SIZE_64: + return true; + default: + return size > SIZE_64; + } + } - public enum Orientation{ - PORT((byte) 0x1), - LAND((byte) 0x2), - SQUARE((byte) 0x3); - private final byte mByteValue; - Orientation(byte b) { - this.mByteValue=b; - } - public byte getByteValue() { - return mByteValue; - } - @Override - public String toString(){ - return name().toLowerCase(); - } - public static Orientation fromValue(byte b){ - for(Orientation orientation:values()){ - if(b==orientation.getByteValue()){ - return orientation; - } - } - return null; - } - public static Orientation fromName(String name){ - if(name==null){ - return null; - } - name=name.trim().toUpperCase(); - for(Orientation orientation:values()){ - if(name.equals(orientation.name())){ - return orientation; - } - } - return null; - } - } - public enum Touchscreen{ - NOTOUCH((byte) 0x1), - STYLUS((byte) 0x2), - FINGER((byte) 0x3); - private final byte mByteValue; - Touchscreen(byte b) { - this.mByteValue=b; - } - public byte getByteValue() { - return mByteValue; - } - @Override - public String toString(){ - return name().toLowerCase(); - } - public static Touchscreen fromValue(byte b){ - for(Touchscreen touchscreen:values()){ - if(b==touchscreen.getByteValue()){ - return touchscreen; - } - } - return null; - } - public static Touchscreen fromName(String name){ - if(name==null){ - return null; - } - name=name.trim().toUpperCase(); - for(Touchscreen touchscreen:values()){ - if(name.equals(touchscreen.name())){ - return touchscreen; - } - } - return null; - } - } - public enum Keyboard{ - NOKEYS((byte) 0x1), - QWERTY((byte) 0x2), - KEY12((byte) 0x3); - private final byte mByteValue; - Keyboard(byte b) { - this.mByteValue=b; - } - public byte getByteValue() { - return mByteValue; - } - @Override - public String toString(){ - if(this==KEY12){ - return "12key"; - } - return name().toLowerCase(); - } - public static Keyboard fromValue(byte b){ - for(Keyboard keyboard:values()){ - if(b==keyboard.getByteValue()){ - return keyboard; - } - } - return null; - } - public static Keyboard fromName(String name){ - if(name==null){ - return null; - } - name=name.trim().toUpperCase(); - if(name.equals("12KEY")){ - return KEY12; - } - for(Keyboard keyboard:values()){ - if(name.equals(keyboard.name())){ - return keyboard; - } - } - return null; - } - } - public enum Navigation{ - NONAV((byte) 0x1), - DPAD((byte) 0x2), - TRACKBALL((byte) 0x3), - WHEEL((byte) 0x4); - private final byte mByteValue; - Navigation(byte b) { - this.mByteValue=b; - } - public byte getByteValue() { - return mByteValue; - } - @Override - public String toString(){ - return name().toLowerCase(); - } - public static Navigation fromValue(byte b){ - for(Navigation navigation:values()){ - if(b==navigation.getByteValue()){ - return navigation; - } - } - return null; - } - public static Navigation fromName(String name){ - if(name==null){ - return null; - } - name=name.trim().toUpperCase(); - for(Navigation navigation:values()){ - if(name.equals(navigation.name())){ - return navigation; - } - } - return null; - } - } - public static final class UiModeType extends Flag{ - public static final int MASK = 0x0f; + public enum Orientation{ + PORT((byte) 0x1), + LAND((byte) 0x2), + SQUARE((byte) 0x3); + private final byte mByteValue; + Orientation(byte b) { + this.mByteValue=b; + } + public byte getByteValue() { + return mByteValue; + } + @Override + public String toString(){ + return name().toLowerCase(); + } + public static Orientation fromValue(byte b){ + for(Orientation orientation:values()){ + if(b==orientation.getByteValue()){ + return orientation; + } + } + return null; + } + public static Orientation fromName(String name){ + if(name==null){ + return null; + } + name=name.trim().toUpperCase(); + for(Orientation orientation:values()){ + if(name.equals(orientation.name())){ + return orientation; + } + } + return null; + } + } + public enum Touchscreen{ + NOTOUCH((byte) 0x1), + STYLUS((byte) 0x2), + FINGER((byte) 0x3); + private final byte mByteValue; + Touchscreen(byte b) { + this.mByteValue=b; + } + public byte getByteValue() { + return mByteValue; + } + @Override + public String toString(){ + return name().toLowerCase(); + } + public static Touchscreen fromValue(byte b){ + for(Touchscreen touchscreen:values()){ + if(b==touchscreen.getByteValue()){ + return touchscreen; + } + } + return null; + } + public static Touchscreen fromName(String name){ + if(name==null){ + return null; + } + name=name.trim().toUpperCase(); + for(Touchscreen touchscreen:values()){ + if(name.equals(touchscreen.name())){ + return touchscreen; + } + } + return null; + } + } + public enum Keyboard{ + NOKEYS((byte) 0x1), + QWERTY((byte) 0x2), + KEY12((byte) 0x3); + private final byte mByteValue; + Keyboard(byte b) { + this.mByteValue=b; + } + public byte getByteValue() { + return mByteValue; + } + @Override + public String toString(){ + if(this==KEY12){ + return "12key"; + } + return name().toLowerCase(); + } + public static Keyboard fromValue(byte b){ + for(Keyboard keyboard:values()){ + if(b==keyboard.getByteValue()){ + return keyboard; + } + } + return null; + } + public static Keyboard fromName(String name){ + if(name==null){ + return null; + } + name=name.trim().toUpperCase(); + if(name.equals("12KEY")){ + return KEY12; + } + for(Keyboard keyboard:values()){ + if(name.equals(keyboard.name())){ + return keyboard; + } + } + return null; + } + } + public enum Navigation{ + NONAV((byte) 0x1), + DPAD((byte) 0x2), + TRACKBALL((byte) 0x3), + WHEEL((byte) 0x4); + private final byte mByteValue; + Navigation(byte b) { + this.mByteValue=b; + } + public byte getByteValue() { + return mByteValue; + } + @Override + public String toString(){ + return name().toLowerCase(); + } + public static Navigation fromValue(byte b){ + for(Navigation navigation:values()){ + if(b==navigation.getByteValue()){ + return navigation; + } + } + return null; + } + public static Navigation fromName(String name){ + if(name==null){ + return null; + } + name=name.trim().toUpperCase(); + for(Navigation navigation:values()){ + if(name.equals(navigation.name())){ + return navigation; + } + } + return null; + } + } + public static final class UiModeType extends Flag{ + public static final int MASK = 0x0f; - public static final UiModeType NORMAL = new UiModeType("normal", 0x01); - public static final UiModeType DESK = new UiModeType("desk", 0x02); - public static final UiModeType CAR = new UiModeType("car", 0x03); - public static final UiModeType TELEVISION = new UiModeType("television", 0x04); - public static final UiModeType APPLIANCE = new UiModeType("appliance", 0x05); - public static final UiModeType WATCH = new UiModeType("watch", 0x06); - public static final UiModeType VRHEADSET = new UiModeType("vrheadset", 0x07); - public static final UiModeType GODZILLAUI = new UiModeType("godzillaui", 0x0b); - public static final UiModeType SMALLUI = new UiModeType("smallui", 0x0c); - public static final UiModeType MEDIUMUI = new UiModeType("mediumui", 0x0d); - public static final UiModeType LARGEUI = new UiModeType("largeui", 0x0e); - public static final UiModeType HUGEUI = new UiModeType("hugeui", 0x0f); + public static final UiModeType NORMAL = new UiModeType("normal", 0x01); + public static final UiModeType DESK = new UiModeType("desk", 0x02); + public static final UiModeType CAR = new UiModeType("car", 0x03); + public static final UiModeType TELEVISION = new UiModeType("television", 0x04); + public static final UiModeType APPLIANCE = new UiModeType("appliance", 0x05); + public static final UiModeType WATCH = new UiModeType("watch", 0x06); + public static final UiModeType VRHEADSET = new UiModeType("vrheadset", 0x07); + public static final UiModeType GODZILLAUI = new UiModeType("godzillaui", 0x0b); + public static final UiModeType SMALLUI = new UiModeType("smallui", 0x0c); + public static final UiModeType MEDIUMUI = new UiModeType("mediumui", 0x0d); + public static final UiModeType LARGEUI = new UiModeType("largeui", 0x0e); + public static final UiModeType HUGEUI = new UiModeType("hugeui", 0x0f); - private static final UiModeType[] VALUES = new UiModeType[]{ - NORMAL, - DESK, - CAR, - TELEVISION, - APPLIANCE, - WATCH, - VRHEADSET, - GODZILLAUI, - SMALLUI, - MEDIUMUI, - LARGEUI, - HUGEUI - }; + private static final UiModeType[] VALUES = new UiModeType[]{ + NORMAL, + DESK, + CAR, + TELEVISION, + APPLIANCE, + WATCH, + VRHEADSET, + GODZILLAUI, + SMALLUI, + MEDIUMUI, + LARGEUI, + HUGEUI + }; - private UiModeType(String name, int flag) { - super(name, flag); - } - public static UiModeType valueOf(int flag){ - return Flag.valueOf(VALUES, MASK, flag); - } - public static UiModeType valueOf(String name){ - return Flag.valueOf(VALUES, name); - } - public static UiModeType fromQualifiers(String qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static UiModeType fromQualifiers(String[] qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static int update(UiModeType flag, int value){ - return Flag.update(MASK, flag, value); - } - } - public static final class UiModeNight extends Flag{ - public static final int MASK = 0x30; - public static final UiModeNight NONIGHT = new UiModeNight("nonight",0x10); - public static final UiModeNight NIGHT = new UiModeNight("night",0x20); - private static final UiModeNight[] VALUES = new UiModeNight[]{ - NONIGHT, - NIGHT - }; - private UiModeNight(String name, int flag) { - super(name, flag); - } - public static UiModeNight valueOf(int flag){ - return Flag.valueOf(VALUES, MASK, flag); - } - public static UiModeNight valueOf(String name){ - return Flag.valueOf(VALUES, name); - } - public static UiModeNight fromQualifiers(String qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static UiModeNight fromQualifiers(String[] qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static int update(UiModeNight flag, int value){ - return Flag.update(MASK, flag, value); - } - } - public static final class ScreenLayoutSize extends Flag{ - public static final int MASK = 0x0f; + private UiModeType(String name, int flag) { + super(name, flag); + } + public static UiModeType valueOf(int flag){ + return Flag.valueOf(VALUES, MASK, flag); + } + public static UiModeType valueOf(String name){ + return Flag.valueOf(VALUES, name); + } + public static UiModeType fromQualifiers(String qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static UiModeType fromQualifiers(String[] qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static int update(UiModeType flag, int value){ + return Flag.update(MASK, flag, value); + } + } + public static final class UiModeNight extends Flag{ + public static final int MASK = 0x30; + public static final UiModeNight NONIGHT = new UiModeNight("nonight",0x10); + public static final UiModeNight NIGHT = new UiModeNight("night",0x20); + private static final UiModeNight[] VALUES = new UiModeNight[]{ + NONIGHT, + NIGHT + }; + private UiModeNight(String name, int flag) { + super(name, flag); + } + public static UiModeNight valueOf(int flag){ + return Flag.valueOf(VALUES, MASK, flag); + } + public static UiModeNight valueOf(String name){ + return Flag.valueOf(VALUES, name); + } + public static UiModeNight fromQualifiers(String qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static UiModeNight fromQualifiers(String[] qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static int update(UiModeNight flag, int value){ + return Flag.update(MASK, flag, value); + } + } + public static final class ScreenLayoutSize extends Flag{ + public static final int MASK = 0x0f; - public static final ScreenLayoutSize SMALL = new ScreenLayoutSize("small", 0x01); - public static final ScreenLayoutSize NORMAL = new ScreenLayoutSize("normal", 0x02); - public static final ScreenLayoutSize LARGE = new ScreenLayoutSize("large", 0x03); - public static final ScreenLayoutSize XLARGE = new ScreenLayoutSize("xlarge", 0x04); - public static final ScreenLayoutSize[] VALUES = new ScreenLayoutSize[]{ - SMALL, - NORMAL, - LARGE, - XLARGE - }; - private ScreenLayoutSize(String name, int flag) { - super(name, flag); - } - public static ScreenLayoutSize valueOf(int flag){ - return Flag.valueOf(VALUES, MASK, flag); - } - public static ScreenLayoutSize valueOf(String name){ - return Flag.valueOf(VALUES, name); - } - public static ScreenLayoutSize fromQualifiers(String qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static ScreenLayoutSize fromQualifiers(String[] qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static int update(ScreenLayoutSize flag, int value){ - return Flag.update(MASK, flag, value); - } - } - public static final class ScreenLayoutLong extends Flag{ - public static final int MASK = 0x30; - public static final ScreenLayoutLong NOTLONG = new ScreenLayoutLong("notlong", 0x10); - public static final ScreenLayoutLong LONG = new ScreenLayoutLong("long", 0x20); - public static final ScreenLayoutLong[] VALUES = new ScreenLayoutLong[]{ - NOTLONG, - LONG - }; - private ScreenLayoutLong(String name, int flag) { - super(name, flag); - } - public static ScreenLayoutLong valueOf(int flag){ - return Flag.valueOf(VALUES, MASK, flag); - } - public static ScreenLayoutLong valueOf(String name){ - return Flag.valueOf(VALUES, name); - } - public static ScreenLayoutLong fromQualifiers(String qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static ScreenLayoutLong fromQualifiers(String[] qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static int update(ScreenLayoutLong flag, int value){ - return Flag.update(MASK, flag, value); - } - } - public static final class ScreenLayoutDir extends Flag{ - public static final int MASK = 0xC0; - public static final ScreenLayoutDir LDLTR = new ScreenLayoutDir("ldltr", 0x40); - public static final ScreenLayoutDir LDRTL = new ScreenLayoutDir("ldrtl", 0x80); - public static final ScreenLayoutDir[] VALUES = new ScreenLayoutDir[]{ - LDLTR, - LDRTL - }; - private ScreenLayoutDir(String name, int flag) { - super(name, flag); - } - public static ScreenLayoutDir valueOf(int flag){ - return Flag.valueOf(VALUES, MASK, flag); - } - public static ScreenLayoutDir valueOf(String name){ - return Flag.valueOf(VALUES, name); - } - public static ScreenLayoutDir fromQualifiers(String qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static ScreenLayoutDir fromQualifiers(String[] qualifiers){ - return Flag.fromQualifiers(VALUES, qualifiers); - } - public static int update(ScreenLayoutDir flag, int value){ - return Flag.update(MASK, flag, value); - } - } + public static final ScreenLayoutSize SMALL = new ScreenLayoutSize("small", 0x01); + public static final ScreenLayoutSize NORMAL = new ScreenLayoutSize("normal", 0x02); + public static final ScreenLayoutSize LARGE = new ScreenLayoutSize("large", 0x03); + public static final ScreenLayoutSize XLARGE = new ScreenLayoutSize("xlarge", 0x04); + public static final ScreenLayoutSize[] VALUES = new ScreenLayoutSize[]{ + SMALL, + NORMAL, + LARGE, + XLARGE + }; + private ScreenLayoutSize(String name, int flag) { + super(name, flag); + } + public static ScreenLayoutSize valueOf(int flag){ + return Flag.valueOf(VALUES, MASK, flag); + } + public static ScreenLayoutSize valueOf(String name){ + return Flag.valueOf(VALUES, name); + } + public static ScreenLayoutSize fromQualifiers(String qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static ScreenLayoutSize fromQualifiers(String[] qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static int update(ScreenLayoutSize flag, int value){ + return Flag.update(MASK, flag, value); + } + } + public static final class ScreenLayoutLong extends Flag{ + public static final int MASK = 0x30; + public static final ScreenLayoutLong NOTLONG = new ScreenLayoutLong("notlong", 0x10); + public static final ScreenLayoutLong LONG = new ScreenLayoutLong("long", 0x20); + public static final ScreenLayoutLong[] VALUES = new ScreenLayoutLong[]{ + NOTLONG, + LONG + }; + private ScreenLayoutLong(String name, int flag) { + super(name, flag); + } + public static ScreenLayoutLong valueOf(int flag){ + return Flag.valueOf(VALUES, MASK, flag); + } + public static ScreenLayoutLong valueOf(String name){ + return Flag.valueOf(VALUES, name); + } + public static ScreenLayoutLong fromQualifiers(String qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static ScreenLayoutLong fromQualifiers(String[] qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static int update(ScreenLayoutLong flag, int value){ + return Flag.update(MASK, flag, value); + } + } + public static final class ScreenLayoutDir extends Flag{ + public static final int MASK = 0xC0; + public static final ScreenLayoutDir LDLTR = new ScreenLayoutDir("ldltr", 0x40); + public static final ScreenLayoutDir LDRTL = new ScreenLayoutDir("ldrtl", 0x80); + public static final ScreenLayoutDir[] VALUES = new ScreenLayoutDir[]{ + LDLTR, + LDRTL + }; + private ScreenLayoutDir(String name, int flag) { + super(name, flag); + } + public static ScreenLayoutDir valueOf(int flag){ + return Flag.valueOf(VALUES, MASK, flag); + } + public static ScreenLayoutDir valueOf(String name){ + return Flag.valueOf(VALUES, name); + } + public static ScreenLayoutDir fromQualifiers(String qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static ScreenLayoutDir fromQualifiers(String[] qualifiers){ + return Flag.fromQualifiers(VALUES, qualifiers); + } + public static int update(ScreenLayoutDir flag, int value){ + return Flag.update(MASK, flag, value); + } + } - static class Flag{ - private final String name; - private final int flag; - Flag(String name, int flag){ - this.name = name; - this.flag = flag; - } - public int getFlag() { - return flag; - } - @Override - public boolean equals(Object obj) { - return obj == this; - } - @Override - public int hashCode() { - return super.hashCode(); - } - @Override - public String toString() { - return name; - } - public static String toString(Flag flag){ - if(flag!=null){ - return flag.toString(); - } - return null; - } - static T fromQualifiers(T[] values, String qualifiers){ - if(qualifiers == null){ - return null; - } - return fromQualifiers(values, qualifiers.split("\\s*-\\s*")); - } - static T fromQualifiers(T[] values, String[] qualifiers){ - if(qualifiers == null){ - return null; - } - for(String name:qualifiers){ - T flag = Flag.valueOf(values, name); - if(flag != null){ - return flag; - } - } - return null; - } - static T valueOf(T[] values, int mask, int flagValue){ - flagValue = flagValue & mask; - for(T flag:values){ - if(flagValue == flag.getFlag()){ - return flag; - } - } - return null; - } - static T valueOf(T[] values, String name){ - if(name == null || name.length()==0){ - return null; - } - if(name.charAt(0)=='-'){ - name = name.substring(1); - } - name = name.toLowerCase(); - for(T flag:values){ - if(name.equals(flag.toString())){ - return flag; - } - } - return null; - } - public static int update(int mask, Flag flag, int value){ - int flip = (~mask) & 0xff; - value = value & flip; - if(flag != null){ - value = value | flag.getFlag(); - } - return value; - } - } + static class Flag{ + private final String name; + private final int flag; + Flag(String name, int flag){ + this.name = name; + this.flag = flag; + } + public int getFlag() { + return flag; + } + @Override + public boolean equals(Object obj) { + return obj == this; + } + @Override + public int hashCode() { + return super.hashCode(); + } + @Override + public String toString() { + return name; + } + public static String toString(Flag flag){ + if(flag!=null){ + return flag.toString(); + } + return null; + } + static T fromQualifiers(T[] values, String qualifiers){ + if(qualifiers == null){ + return null; + } + return fromQualifiers(values, qualifiers.split("\\s*-\\s*")); + } + static T fromQualifiers(T[] values, String[] qualifiers){ + if(qualifiers == null){ + return null; + } + for(String name:qualifiers){ + T flag = Flag.valueOf(values, name); + if(flag != null){ + return flag; + } + } + return null; + } + static T valueOf(T[] values, int mask, int flagValue){ + flagValue = flagValue & mask; + for(T flag:values){ + if(flagValue == flag.getFlag()){ + return flag; + } + } + return null; + } + static T valueOf(T[] values, String name){ + if(name == null || name.length()==0){ + return null; + } + if(name.charAt(0)=='-'){ + name = name.substring(1); + } + name = name.toLowerCase(); + for(T flag:values){ + if(name.equals(flag.toString())){ + return flag; + } + } + return null; + } + public static int update(int mask, Flag flag, int value){ + int flip = (~mask) & 0xff; + value = value & flip; + if(flag != null){ + value = value | flag.getFlag(); + } + return value; + } + } - public static final int SIZE_16 = 16; - public static final int SIZE_28 = 28; - public static final int SIZE_32 = 32; - public static final int SIZE_36 = 36; - public static final int SIZE_48 = 48; - public static final int SIZE_52 = 52; - public static final int SIZE_56 = 56; - public static final int SIZE_64 = 64; + public static final int SIZE_16 = 16; + public static final int SIZE_28 = 28; + public static final int SIZE_32 = 32; + public static final int SIZE_36 = 36; + public static final int SIZE_48 = 48; + public static final int SIZE_52 = 52; + public static final int SIZE_56 = 56; + public static final int SIZE_64 = 64; - private static final int OFFSET_mcc = 0; - private static final int OFFSET_mnc = 2; - private static final int OFFSET_language = 4; - private static final int OFFSET_region = 6; - private static final int OFFSET_orientation = 8; - private static final int OFFSET_touchscreen = 9; - private static final int OFFSET_density = 10; - //SIZE=16 - private static final int OFFSET_keyboard = 12; - private static final int OFFSET_navigation = 13; - private static final int OFFSET_inputFlags = 14; - private static final int OFFSET_inputPad0 = 15; - private static final int OFFSET_screenWidth = 16; - private static final int OFFSET_screenHeight = 18; - private static final int OFFSET_sdkVersion = 20; - private static final int OFFSET_minorVersion = 22; - //SIZE=28 - private static final int OFFSET_screenLayout = 24; - private static final int OFFSET_uiMode = 25; - private static final int OFFSET_smallestScreenWidthDp = 26; - //SIZE=32 - private static final int OFFSET_screenWidthDp = 28; - private static final int OFFSET_screenHeightDp = 30; - //SIZE=36 - private static final int OFFSET_localeScript = 32; - private static final int OFFSET_localeVariant = 36; - //SIZE=48 - private static final int OFFSET_screenLayout2 = 44; - private static final int OFFSET_colorMode = 45; - private static final int OFFSET_reservedPadding = 46; - //SIZE=52 - private static final int OFFSET_endBlock = 52; + private static final int OFFSET_mcc = 0; + private static final int OFFSET_mnc = 2; + private static final int OFFSET_language = 4; + private static final int OFFSET_region = 6; + private static final int OFFSET_orientation = 8; + private static final int OFFSET_touchscreen = 9; + private static final int OFFSET_density = 10; + //SIZE=16 + private static final int OFFSET_keyboard = 12; + private static final int OFFSET_navigation = 13; + private static final int OFFSET_inputFlags = 14; + private static final int OFFSET_inputPad0 = 15; + private static final int OFFSET_screenWidth = 16; + private static final int OFFSET_screenHeight = 18; + private static final int OFFSET_sdkVersion = 20; + private static final int OFFSET_minorVersion = 22; + //SIZE=28 + private static final int OFFSET_screenLayout = 24; + private static final int OFFSET_uiMode = 25; + private static final int OFFSET_smallestScreenWidthDp = 26; + //SIZE=32 + private static final int OFFSET_screenWidthDp = 28; + private static final int OFFSET_screenHeightDp = 30; + //SIZE=36 + private static final int OFFSET_localeScript = 32; + private static final int OFFSET_localeVariant = 36; + //SIZE=48 + private static final int OFFSET_screenLayout2 = 44; + private static final int OFFSET_colorMode = 45; + private static final int OFFSET_reservedPadding = 46; + //SIZE=52 + private static final int OFFSET_endBlock = 52; - private static final int LEN_localeScript = 4; - private static final int LEN_localeVariant = 8; + private static final int LEN_localeScript = 4; + private static final int LEN_localeVariant = 8; - private static final String NAME_mcc = "mcc"; - private static final String NAME_mnc = "mnc"; - private static final String NAME_language = "language"; - private static final String NAME_region = "region"; - private static final String NAME_orientation = "orientation"; - private static final String NAME_touchscreen = "touchscreen"; - private static final String NAME_density = "density"; - //SIZE=16 - private static final String NAME_keyboard = "keyboard"; - private static final String NAME_navigation = "navigation"; - private static final String NAME_inputFlags = "inputFlags"; - private static final String NAME_inputPad0 = "inputPad0"; - private static final String NAME_screenWidth = "screenWidth"; - private static final String NAME_screenHeight = "screenHeight"; - private static final String NAME_sdkVersion = "sdkVersion"; - private static final String NAME_minorVersion = "minorVersion"; - //SIZE=28 - private static final String NAME_screen_layout_size = "screen_layout_size"; - private static final String NAME_screen_layout_long = "screen_layout_long"; - private static final String NAME_screen_layout_dir = "screen_layout_dir"; - private static final String NAME_ui_mode_type = "ui_mode_type"; - private static final String NAME_ui_mode_night = "ui_mode_night"; - private static final String NAME_smallestScreenWidthDp = "smallestScreenWidthDp"; - //SIZE=32 = ""; - private static final String NAME_screenWidthDp = "screenWidthDp"; - private static final String NAME_screenHeightDp = "screenHeightDp"; - //SIZE=36 - private static final String NAME_localeScript = "localeScript"; - private static final String NAME_localeVariant = "localeVariant"; - private static final String NAME_screenLayout2 = "screenLayout2"; - private static final String NAME_colorMode = "colorMode"; + private static final String NAME_mcc = "mcc"; + private static final String NAME_mnc = "mnc"; + private static final String NAME_language = "language"; + private static final String NAME_region = "region"; + private static final String NAME_orientation = "orientation"; + private static final String NAME_touchscreen = "touchscreen"; + private static final String NAME_density = "density"; + //SIZE=16 + private static final String NAME_keyboard = "keyboard"; + private static final String NAME_navigation = "navigation"; + private static final String NAME_inputFlags = "inputFlags"; + private static final String NAME_inputPad0 = "inputPad0"; + private static final String NAME_screenWidth = "screenWidth"; + private static final String NAME_screenHeight = "screenHeight"; + private static final String NAME_sdkVersion = "sdkVersion"; + private static final String NAME_minorVersion = "minorVersion"; + //SIZE=28 + private static final String NAME_screen_layout_size = "screen_layout_size"; + private static final String NAME_screen_layout_long = "screen_layout_long"; + private static final String NAME_screen_layout_dir = "screen_layout_dir"; + private static final String NAME_ui_mode_type = "ui_mode_type"; + private static final String NAME_ui_mode_night = "ui_mode_night"; + private static final String NAME_smallestScreenWidthDp = "smallestScreenWidthDp"; + //SIZE=32 = ""; + private static final String NAME_screenWidthDp = "screenWidthDp"; + private static final String NAME_screenHeightDp = "screenHeightDp"; + //SIZE=36 + private static final String NAME_localeScript = "localeScript"; + private static final String NAME_localeVariant = "localeVariant"; + private static final String NAME_screenLayout2 = "screenLayout2"; + private static final String NAME_colorMode = "colorMode"; - private static final char POSTFIX_locale = '#'; + private static final char POSTFIX_locale = '#'; -} + }