List of usage examples for android.hardware.camera2 CameraMetadata getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.android.camera2.its.ItsSerializer.java
private static Object getKeyValue(CameraMetadata md, Object keyObj) throws ItsException { if (md.getClass() == CaptureResult.class || md.getClass() == TotalCaptureResult.class) { return ((CaptureResult) md).get((CaptureResult.Key) keyObj); } else if (md.getClass() == CaptureRequest.class) { return ((CaptureRequest) md).get((CaptureRequest.Key) keyObj); } else if (md.getClass() == CameraCharacteristics.class) { return ((CameraCharacteristics) md).get((CameraCharacteristics.Key) keyObj); }//from ww w . j av a2 s . c o m throw new ItsException("Invalid key object"); }
From source file:com.android.camera2.its.ItsSerializer.java
@SuppressWarnings("unchecked") public static JSONObject serialize(CameraMetadata md) throws ItsException { JSONObject jsonObj = new JSONObject(); Field[] allFields = md.getClass().getDeclaredFields(); if (md.getClass() == TotalCaptureResult.class) { allFields = CaptureResult.class.getDeclaredFields(); }//from ww w . j ava2 s .c o m for (Field field : allFields) { if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && (field.getType() == CaptureRequest.Key.class || field.getType() == CaptureResult.Key.class || field.getType() == TotalCaptureResult.Key.class || field.getType() == CameraCharacteristics.Key.class) && field.getGenericType() instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) field.getGenericType(); Type[] argTypes = paramType.getActualTypeArguments(); if (argTypes.length > 0) { try { Type keyType = argTypes[0]; Object keyObj = field.get(md); MetadataEntry entry; if (keyType instanceof GenericArrayType) { entry = serializeArrayEntry(keyType, keyObj, md); } else { entry = serializeEntry(keyType, keyObj, md); } // TODO: Figure this weird case out. // There is a weird case where the entry is non-null but the toString // of the entry is null, and if this happens, the null-ness spreads like // a virus and makes the whole JSON object null from the top level down. // Not sure if it's a bug in the library or I'm just not using it right. // Workaround by checking for this case explicitly and not adding the // value to the jsonObj when it is detected. if (entry != null && entry.key != null && entry.value != null && entry.value.toString() == null) { Logt.w(TAG, "Error encountered serializing value for key: " + entry.key); } else if (entry != null) { jsonObj.put(entry.key, entry.value); } else { // Ignore. } } catch (IllegalAccessException e) { throw new ItsException("Access error for field: " + field + ": ", e); } catch (org.json.JSONException e) { throw new ItsException("JSON error for field: " + field + ": ", e); } } } } return jsonObj; }