Trying to educate myself from a sample Android app in Android Studio, I have found an ArrayList<String>.
In the debugging mode, the value(s) of this array is as below (using the view tool of the IDE)
I don't really understand how to recognize each element of the array.
I would appreciate any help.
The list is constructed as below (from a JSON file).
public static List<ArrayList<String>> getPrintDataFromJson(Context context, String jsonFileName, int copies, float multiple) {
try {
String jsonContent = AssetJsonReader.readJsonFromAssets(context, jsonFileName,
error -> Log.e(TAG, "Json not found: " + jsonFileName + ", error: " + error));
if (jsonContent == null || jsonContent.isEmpty()) {
Log.e(TAG, "JSON is empty: " + jsonFileName);
return null;
}
return parseJsonToPrintData(jsonContent, copies, multiple);
} catch (Exception e) {
Log.e(TAG, "Cannot get data from Json: " + jsonFileName, e);
return null;
}
}
and...
private static List<ArrayList<String>> parseJsonToPrintData(String jsonContent, int copies, float multiple) {
try {
List<PrintTemplate> templates = null;
try {
PrintTemplate[] templateArray = JsonProcessor.GSON_INSTANCE.fromJson(jsonContent, PrintTemplate[].class);
if (templateArray != null && templateArray.length > 0) {
templates = new ArrayList<>();
Collections.addAll(templates, templateArray);
}
} catch (Exception e) {
try {
PrintTemplate template = JsonProcessor.GSON_INSTANCE.fromJson(jsonContent, PrintTemplate.class);
if (template != null) {
templates = new ArrayList<>();
templates.add(template);
}
} catch (Exception ex) {
Log.e(TAG, "Unable to parse JSON as a PrintTemplate object or array", ex);
return null;
}
}
if (templates == null || templates.isEmpty()) {
Log.e(TAG, "There is no valid template data in the JSON.");
return null;
}
List<String> processedJsonData = JsonProcessor.processTemplateList(templates);
int templateLength = templates.size();
List<PrinterImageProcessingInfoWrapper> infoWrappers = new ArrayList<>();
for (int i = 0; i < templateLength; i++) {
infoWrappers.add(createPrinterImageProcessingInfoWrapper(templates.get(i), copies, multiple));
}
List<String> processedInfoData = JsonProcessor.processInfoWrapperList(infoWrappers);
List<ArrayList<String>> printData = new ArrayList<>();
printData.add(new ArrayList<>(processedJsonData));
printData.add(new ArrayList<>(processedInfoData));
return printData;
} catch (JsonSyntaxException e) {
Log.e(TAG, "JSON syntax error", e);
return null;
} catch (Exception e) {
Log.e(TAG, "Parsing JSON content failed to print data", e);
return null;
}
}
and the result in the list is as below.
{
"width" : 40.0,
"height" : 20.0,
"rotate" : 0,
"background" : "",
"backgroundImage" : "",
"elements" : [ {
"type" : "barcode",
"x" : 2.0,
"y" : 2.0,
"width" : 36.0,
"height" : 16.0,
"rotate" : 0,
"codeType" : 20,
"value" : "6942141752896",
"fontSize" : 3.200000047683716,
"textHeight" : 3.200000047683716,
"textPosition" : 0,
"zIndex" : 0,
"isTitle" : 0
},{
"type" : "text",
"x" : 2.0,
"y" : 2.0,
"width" : 36.0,
"height" : 7.400000095367432,
"rotate" : 0,
"value" : "Certificate",
"fontCode" : "",
"fontFamily" : "",
"fontSize" : 5.599999904632568,
"textAlignHorizonral" : 1,
"textAlignVertical" : 1,
"lineMode" : 9,
"letterSpacing" : 0.0,
"lineSpacing" : 1.0,
"typesettingMode" : 1,
"colorReverse" : 0,
"zIndex" : 101,
"wordSpacing" : 0,
"lineBreakMode" : 1,
"isTitle" : 0,
"fontStyle" : [ "bold" ]
} ]
ArrayList<String>?