2019-10-16 07:49:58 +02:00
|
|
|
/*
|
2019-07-13 18:19:41 +02:00
|
|
|
* Copyright (C) 2019 Ryszard Wiśniewski <brut.alll@gmail.com>
|
|
|
|
* Copyright (C) 2019 Connor Tumbleson <connor.tumbleson@gmail.com>
|
2012-09-20 03:27:35 +02:00
|
|
|
*
|
|
|
|
* 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 brut.androlib.res.decoder;
|
|
|
|
|
|
|
|
import brut.androlib.AndrolibException;
|
2015-05-10 14:36:44 +02:00
|
|
|
import brut.androlib.err.UndefinedResObject;
|
2012-09-20 03:27:35 +02:00
|
|
|
import brut.androlib.res.data.ResPackage;
|
2014-06-18 17:59:54 +02:00
|
|
|
import brut.androlib.res.data.ResResSpec;
|
2012-09-20 03:27:35 +02:00
|
|
|
import brut.androlib.res.data.value.ResAttr;
|
|
|
|
import brut.androlib.res.data.value.ResScalarValue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
|
|
|
*/
|
|
|
|
public class ResAttrDecoder {
|
2014-02-10 02:01:57 +01:00
|
|
|
public String decode(int type, int value, String rawValue, int attrResId)
|
|
|
|
throws AndrolibException {
|
|
|
|
ResScalarValue resValue = mCurrentPackage.getValueFactory().factory(
|
|
|
|
type, value, rawValue);
|
|
|
|
|
|
|
|
String decoded = null;
|
2015-05-10 14:36:44 +02:00
|
|
|
if (attrResId > 0) {
|
|
|
|
try {
|
|
|
|
ResAttr attr = (ResAttr) getCurrentPackage().getResTable()
|
|
|
|
.getResSpec(attrResId).getDefaultResource().getValue();
|
|
|
|
|
|
|
|
decoded = attr.convertToResXmlFormat(resValue);
|
2015-10-15 15:58:19 +02:00
|
|
|
} catch (UndefinedResObject | ClassCastException ex) {
|
2015-05-10 14:36:44 +02:00
|
|
|
// ignored
|
|
|
|
}
|
2014-02-10 02:01:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return decoded != null ? decoded : resValue.encodeAsResXmlAttr();
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:59:54 +02:00
|
|
|
public String decodeManifestAttr(int attrResId)
|
|
|
|
throws AndrolibException {
|
|
|
|
|
|
|
|
if (attrResId != 0) {
|
|
|
|
ResResSpec resResSpec = getCurrentPackage().getResTable().getResSpec(attrResId);
|
|
|
|
|
|
|
|
if (resResSpec != null) {
|
|
|
|
return resResSpec.getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:01:57 +01:00
|
|
|
public ResPackage getCurrentPackage() throws AndrolibException {
|
|
|
|
if (mCurrentPackage == null) {
|
|
|
|
throw new AndrolibException("Current package not set");
|
|
|
|
}
|
|
|
|
return mCurrentPackage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentPackage(ResPackage currentPackage) {
|
|
|
|
mCurrentPackage = currentPackage;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ResPackage mCurrentPackage;
|
2012-09-20 03:27:35 +02:00
|
|
|
}
|