SpecFlag.java
1 /* 2 * Copyright (C) 2022 github.com/REAndroid 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.reandroid.arsc.item; 17 18 import com.reandroid.arsc.chunk.SpecBlock; 19 import com.reandroid.utils.HexUtil; 20 21 public class SpecFlag extends IndirectItem<SpecFlagsArray> { 22 public SpecFlag(SpecFlagsArray specFlagsArray, int offset) { 23 super(specFlagsArray, offset); 24 } 25 public byte getFlagByte(){ 26 return getBlockItem().getBytesInternal()[getOffset() + OFFSET_FLAG]; 27 } 28 public void setFlagByte(byte flag){ 29 getBlockItem().getBytesInternal()[getOffset() + OFFSET_FLAG] = flag; 30 } 31 public void addFlagByte(byte flag){ 32 flag = (byte) ((getFlagByte() & 0xff) | (flag & 0xff)); 33 setFlagByte(flag); 34 } 35 public void addFlag(SpecBlock.Flag flag){ 36 addFlagByte(flag.getFlag()); 37 } 38 public void setPublic(){ 39 addFlag(SpecBlock.Flag.SPEC_PUBLIC); 40 } 41 public boolean isPublic(){ 42 return SpecBlock.Flag.isPublic(getFlagByte()); 43 } 44 public int getInteger(){ 45 return BlockItem.getInteger(this.getBlockItem().getBytesInternal(), this.getOffset()); 46 } 47 public void setInteger(int value){ 48 if(value == getInteger()){ 49 return; 50 } 51 BlockItem.putInteger(this.getBlockItem().getBytesInternal(), this.getOffset(), value); 52 this.getBlockItem().onBytesChanged(); 53 } 54 @Override 55 public String toString(){ 56 byte flag = getFlagByte(); 57 if(flag != 0){ 58 return SpecBlock.Flag.toString(getFlagByte()); 59 } 60 int val = getInteger(); 61 if(val != 0){ 62 return HexUtil.toHex8(val); 63 } 64 return ""; 65 } 66 67 private static final int OFFSET_FLAG = 3; 68 69 }