diff --git a/src/main/java/com/reandroid/apk/SingleJsonTableInputSource.java b/src/main/java/com/reandroid/apk/SingleJsonTableInputSource.java index 6ac7a77..1cc1129 100644 --- a/src/main/java/com/reandroid/apk/SingleJsonTableInputSource.java +++ b/src/main/java/com/reandroid/apk/SingleJsonTableInputSource.java @@ -1,4 +1,4 @@ - /* +/* * Copyright (C) 2022 github.com/REAndroid * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,22 +52,22 @@ public class SingleJsonTableInputSource extends InputSource { return outputStream.getCrcValue(); } public TableBlock getTableBlock() throws IOException{ - if(mCache!=null){ + if(mCache != null){ return mCache; } - logMessage("Building resources table: "+inputSource.getAlias()); + logMessage("Building resources table: " + inputSource.getAlias()); TableBlock tableBlock=newInstance(); - InputStream inputStream=inputSource.openStream(); + InputStream inputStream = inputSource.openStream(); try{ - StringPoolBuilder poolBuilder=new StringPoolBuilder(); - JSONObject jsonObject=new JSONObject(inputStream); + StringPoolBuilder poolBuilder = new StringPoolBuilder(); + JSONObject jsonObject = new JSONObject(inputStream); poolBuilder.build(jsonObject); poolBuilder.apply(tableBlock); tableBlock.fromJson(jsonObject); }catch (JSONException ex){ - throw new IOException(inputSource.getAlias()+": "+ex.getMessage()); + throw new IOException(inputSource.getAlias(), ex); } - mCache=tableBlock; + mCache = tableBlock; return tableBlock; } TableBlock newInstance(){ diff --git a/src/main/java/com/reandroid/apk/StringPoolBuilder.java b/src/main/java/com/reandroid/apk/StringPoolBuilder.java index 6e7c328..2182582 100644 --- a/src/main/java/com/reandroid/apk/StringPoolBuilder.java +++ b/src/main/java/com/reandroid/apk/StringPoolBuilder.java @@ -1,4 +1,4 @@ - /* +/* * Copyright (C) 2022 github.com/REAndroid * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/main/java/com/reandroid/arsc/item/StringItem.java b/src/main/java/com/reandroid/arsc/item/StringItem.java index 1e6269e..bf3271c 100755 --- a/src/main/java/com/reandroid/arsc/item/StringItem.java +++ b/src/main/java/com/reandroid/arsc/item/StringItem.java @@ -254,15 +254,17 @@ public class StringItem extends BlockItem implements JSONConvert { if(isNull()){ return null; } + StyleItem styleItem=getStyle(); + if(styleItem == null){ + return null; + } JSONObject jsonObject=new JSONObject(); jsonObject.put(NAME_string, get()); - StyleItem styleItem=getStyle(); - if(styleItem!=null){ - JSONObject styleJson=styleItem.toJson(); - if(styleJson!=null){ - jsonObject.put(NAME_style, styleJson); - } + JSONObject styleJson = styleItem.toJson(); + if(styleJson == null){ + return null; } + jsonObject.put(NAME_style, styleJson); return jsonObject; } @Override diff --git a/src/main/java/com/reandroid/arsc/pool/JsonStringPoolHelper.java b/src/main/java/com/reandroid/arsc/pool/JsonStringPoolHelper.java index da20b00..2f69fbc 100644 --- a/src/main/java/com/reandroid/arsc/pool/JsonStringPoolHelper.java +++ b/src/main/java/com/reandroid/arsc/pool/JsonStringPoolHelper.java @@ -1,3 +1,18 @@ +/* + * 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.pool; import com.reandroid.arsc.array.StringArray; @@ -88,15 +103,21 @@ class JsonStringPoolHelper { } static List fromJson(JSONArray jsonArray){ int length = jsonArray.length(); - List results=new ArrayList<>(); - for(int i=0;i results = new ArrayList<>(length); + for(int i=0; i < length; i++){ + StyledString styledString = + fromJson(jsonArray.getJSONObject(i)); + if(styledString != null){ + results.add(styledString); + } } return results; } - static StyledString fromJson(JSONObject jsonObject){ - String text= jsonObject.getString(StringItem.NAME_string); + private static StyledString fromJson(JSONObject jsonObject){ + if(!jsonObject.has(StringItem.NAME_style)){ + return null; + } + String text = jsonObject.getString(StringItem.NAME_string); JSONObject style=jsonObject.getJSONObject(StringItem.NAME_style); JSONArray spansArray=style.getJSONArray(StyleItem.NAME_spans); List spanInfoList = toSpanInfoList(spansArray); @@ -107,7 +128,7 @@ class JsonStringPoolHelper { List results=new ArrayList<>(length); for(int i=0;i