List of usage examples for com.google.gson JsonNull INSTANCE
JsonNull INSTANCE
To view the source code for com.google.gson JsonNull INSTANCE.
Click Source Link
From source file:hd3gtv.mydmam.manager.GsonThrowable.java
License:Open Source License
private static JsonObject toJson(Throwable src) { JsonObject result = new JsonObject(); result.addProperty("message", src.getMessage()); result.addProperty("class", src.getClass().getName()); if (src.getCause() != null) { result.add("cause", toJson(src.getCause())); } else {// w ww .j a v a 2 s . co m result.add("cause", JsonNull.INSTANCE); } JsonArray ja_stacktrace = new JsonArray(); StackTraceElement[] stack_trace = src.getStackTrace(); StackTraceElement trace; for (int pos = 0; pos < stack_trace.length; pos++) { trace = stack_trace[pos]; JsonObject jo_trace = new JsonObject(); jo_trace.addProperty("class", trace.getClassName()); jo_trace.addProperty("method", trace.getMethodName()); if (trace.getFileName() != null) { jo_trace.addProperty("file", trace.getFileName()); } jo_trace.addProperty("line", trace.getLineNumber()); ja_stacktrace.add(jo_trace); } result.add("stacktrace", ja_stacktrace); return result; }
From source file:ideal.showcase.coach.marshallers.marshaller.java
License:Open Source License
private JsonElement to_json_value(value_wrapper v) { if (v instanceof data_value) { return to_json_data((data_value) v); } else if (v instanceof enum_value) { return to_json_enum((enum_value) v); } else if (v instanceof list_wrapper) { return to_json_list((list_wrapper) v); } else if (v instanceof string_value) { return to_json_string(((string_value) v).unwrap()); } else if (v == null) { return JsonNull.INSTANCE; }/*from ww w . j a va 2 s . c o m*/ throw new RuntimeException(); }
From source file:im.neon.adapters.VectorSearchMessagesListAdapter.java
License:Apache License
@Override public View getView(int position, View convertView2, ViewGroup parent) { View convertView = super.getView(position, convertView2, parent); MessageRow row = getItem(position);// www . j a va 2 s . co m Event event = row.getEvent(); // some items are always hidden convertView.findViewById(R.id.messagesAdapter_avatars_list).setVisibility(View.GONE); convertView.findViewById(R.id.messagesAdapter_message_separator).setVisibility(View.GONE); convertView.findViewById(R.id.messagesAdapter_action_image).setVisibility(View.GONE); convertView.findViewById(R.id.messagesAdapter_top_margin_when_no_room_name) .setVisibility(mDisplayRoomName ? View.GONE : View.VISIBLE); convertView.findViewById(R.id.messagesAdapter_message_header).setVisibility(View.GONE); Room room = mSession.getDataHandler().getStore().getRoom(event.roomId); RoomState roomState = row.getRoomState(); if (null == roomState) { roomState = room.getLiveState(); } RoomMember sender = null; if (null != roomState) { sender = roomState.getMember(event.getSender()); } // refresh the avatar ImageView avatarView = (ImageView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_left) .findViewById(R.id.avatar_img); String url = null; // Check whether this avatar url is updated by the current event (This happens in case of new joined member) JsonObject msgContent = event.getContentAsJsonObject(); if (msgContent.has("avatar_url")) { url = msgContent.get("avatar_url") == JsonNull.INSTANCE ? null : msgContent.get("avatar_url").getAsString(); } String displayName = null; // if (msgContent.has("displayname")) { displayName = msgContent.get("displayname") == JsonNull.INSTANCE ? null : msgContent.get("displayname").getAsString(); } loadMemberAvatar(avatarView, sender, event.getSender(), displayName, url); // display the sender TextView senderTextView = (TextView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_sender); senderTextView.setText(getUserDisplayName(event.getSender(), roomState)); // display the body TextView bodyTextView = (TextView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body); // set the message text EventDisplay display = new EventDisplay(mContext, event, (null != room) ? room.getLiveState() : null); CharSequence text = display.getTextualDisplay(); if (null == text) { text = ""; } try { highlightPattern(bodyTextView, new SpannableString(text), mPattern); } catch (Exception e) { // an exception might be triggered with HTML content // Indeed, the formatting can fail because of the single line display. // in this case, the formatting is ignored. bodyTextView.setText(text.toString()); } // display timestamp TextView timeTextView = (TextView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp); timeTextView.setText(AdapterUtils.tsToString(mContext, event.getOriginServerTs(), true)); // display the room name View roomNameLayout = convertView.findViewById(R.id.messagesAdapter_message_room_name_layout); roomNameLayout.setVisibility(mDisplayRoomName ? View.VISIBLE : View.GONE); if (mDisplayRoomName) { TextView roomTextView = (TextView) convertView .findViewById(R.id.messagesAdapter_message_room_name_textview); roomTextView.setText(VectorUtils.getRoomDisplayName(mContext, mSession, room)); } // display the day View dayLayout = convertView.findViewById(R.id.messagesAdapter_search_message_day_separator); // day separator String headerMessage = headerMessage(position); if (!TextUtils.isEmpty(headerMessage)) { dayLayout.setVisibility(View.VISIBLE); TextView headerText = (TextView) convertView.findViewById(R.id.messagesAdapter_message_header_text); headerText.setText(headerMessage); dayLayout.findViewById(R.id.messagesAdapter_message_header_top_margin).setVisibility(View.GONE); dayLayout.findViewById(R.id.messagesAdapter_message_header_bottom_margin).setVisibility(View.GONE); } else { dayLayout.setVisibility(View.GONE); } // message separator is only displayed when a message is not the last message in a day section convertView.findViewById(R.id.messagesAdapter_search_separator_line) .setVisibility(!TextUtils.isEmpty(headerMessage(position + 1)) ? View.GONE : View.VISIBLE); final int fPosition = position; convertView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != mMessagesAdapterEventsListener) { mMessagesAdapterEventsListener.onContentClick(fPosition); } } }); convertView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (null != mMessagesAdapterEventsListener) { return mMessagesAdapterEventsListener.onContentLongClick(fPosition); } return false; } }); return convertView; }
From source file:im.vector.adapters.ConsoleMessagesAdapter.java
License:Apache License
@Override protected boolean manageSubView(int position, View convertView, View subView, int msgType) { MessageRow row = getItem(position);/*from ww w . java 2 s. com*/ Event msg = row.getEvent(); RoomState roomState = row.getRoomState(); MyUser myUser = mSession.getMyUser(); // isMergedView -> the message is going to be merged with the previous one // willBeMerged -> false if it is the last message of the user boolean isMergedView = false; boolean willBeMerged = false; convertView.setClickable(false); // the notice messages are never merged /*if (msgType != ROW_TYPE_NOTICE)*/ { // Date prevMsgDate = null; String prevUserId = null; if (position > 0) { MessageRow prevRow = getItem(position - 1); if ((null != prevRow) /*&& (getItemViewType(prevRow.getEvent()) != ROW_TYPE_NOTICE)*/) { prevUserId = prevRow.getEvent().userId; prevMsgDate = mMessagesDateList.get(position - 1); } } Date nextMsgDate = null; String nextUserId = null; if ((position + 1) < this.getCount()) { MessageRow nextRow = getItem(position + 1); if ((null != nextRow) /*&& (getItemViewType(nextRow.getEvent()) != ROW_TYPE_NOTICE)*/) { nextUserId = nextRow.getEvent().userId; nextMsgDate = mMessagesDateList.get(position + 1); } } Date curMsgDate = mMessagesDateList.get(position); isMergedView = (null != prevUserId) && (prevUserId.equals(msg.userId)); // no not merge message from different day if (isMergedView) { if (null != prevMsgDate) { isMergedView = (curMsgDate.getTime() == prevMsgDate.getTime()); } } willBeMerged = (null != nextUserId) && (nextUserId.equals(msg.userId)); // no not merge message from different day if (willBeMerged) { if (null != nextMsgDate) { willBeMerged = (curMsgDate.getTime() == nextMsgDate.getTime()); } } } View leftTsTextLayout = convertView.findViewById(org.matrix.androidsdk.R.id.message_timestamp_layout_left); View rightTsTextLayout = convertView .findViewById(org.matrix.androidsdk.R.id.message_timestamp_layout_right); // manage sender text TextView textView = (TextView) convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_sender); if (null != textView) { if (null == rightTsTextLayout) { textView.setVisibility(View.VISIBLE); if (isMergedView) { textView.setText(""); } else { textView.setText(getUserDisplayName(msg.userId, row.getRoomState())); } } else if (isMergedView || (msgType == ROW_TYPE_NOTICE)) { textView.setVisibility(View.GONE); } else { textView.setVisibility(View.VISIBLE); textView.setText(getUserDisplayName(msg.userId, row.getRoomState())); } final String fSenderId = msg.userId; final String fDisplayName = textView.getText().toString(); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSenderNameClick(fSenderId, fDisplayName); } }); } TextView tsTextView; if (null == rightTsTextLayout) { tsTextView = (TextView) leftTsTextLayout .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp); } else { TextView leftTsTextView = (TextView) leftTsTextLayout .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp); TextView rightTsTextView = (TextView) rightTsTextLayout .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp); leftTsTextView.setVisibility(View.GONE); tsTextView = rightTsTextView; } tsTextView.setVisibility(View.VISIBLE); tsTextView.setText(msg.formattedOriginServerTs()); if (row.getEvent().isUndeliverable()) { tsTextView.setTextColor(notSentColor); } else { tsTextView.setTextColor(mContext.getResources().getColor(org.matrix.androidsdk.R.color.chat_gray_text)); } // Sender avatar RoomMember sender = roomState.getMember(msg.userId); View avatarLeftView = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_left); View avatarRightView = convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_right); // does the layout display the avatar ? if ((null != avatarLeftView) && (null != avatarRightView)) { View avatarLayoutView = null; avatarLayoutView = avatarLeftView; avatarRightView.setVisibility(View.GONE); final String userId = msg.userId; final String roomId = roomState.roomId; avatarLeftView.setClickable(true); avatarLeftView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return onAvatarLongClick(roomId, userId); } }); // click on the avatar opens the details page avatarLeftView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onAvatarClick(roomId, userId); } }); ImageView avatarImageView = (ImageView) avatarLayoutView .findViewById(org.matrix.androidsdk.R.id.avatar_img); ImageView presenceView = (ImageView) avatarLayoutView .findViewById(org.matrix.androidsdk.R.id.imageView_presenceRing); presenceView.setColorFilter(mContext.getResources().getColor(android.R.color.transparent)); updatePresenceRing(presenceView, userId); if (isMergedView) { avatarLayoutView.setVisibility(View.GONE); } else { avatarLayoutView.setVisibility(View.VISIBLE); avatarImageView.setTag(null); avatarImageView.setImageResource(org.matrix.androidsdk.R.drawable.ic_contact_picture_holo_light); String url = null; // Check whether this avatar url is updated by the current event (This happens in case of new joined member) if (msg.content.has("avatar_url")) { url = msg.content.get("avatar_url") == JsonNull.INSTANCE ? null : msg.content.get("avatar_url").getAsString(); } if ((sender != null) && (null == url)) { url = sender.avatarUrl; } if (TextUtils.isEmpty(url) && (null != msg.userId)) { url = ContentManager.getIdenticonURL(msg.userId); } if (!TextUtils.isEmpty(url)) { loadAvatar(avatarImageView, url); } // display the typing icon when required ImageView typingImage = (ImageView) avatarLayoutView .findViewById(org.matrix.androidsdk.R.id.avatar_typing_img); typingImage.setVisibility(((mTypingUsers.indexOf(msg.userId) >= 0)) ? View.VISIBLE : View.GONE); } // if the messages are merged // the thumbnail is hidden // and the subview must be moved to be aligned with the previous body View bodyLayoutView = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout); ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView .getLayoutParams(); FrameLayout.LayoutParams subViewLinearLayout = (FrameLayout.LayoutParams) subView.getLayoutParams(); View view = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_left); ViewGroup.LayoutParams avatarLayout = view.getLayoutParams(); subViewLinearLayout.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL; if (isMergedView) { bodyLayout.setMargins(avatarLayout.width, bodyLayout.topMargin, 4, bodyLayout.bottomMargin); } else { bodyLayout.setMargins(4, bodyLayout.topMargin, 4, bodyLayout.bottomMargin); } subView.setLayoutParams(bodyLayout); bodyLayoutView.setLayoutParams(bodyLayout); subView.setLayoutParams(subViewLinearLayout); view = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator); if (null != view) { View line = convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator_line); if (null != line) { line.setBackgroundColor(Color.TRANSPARENT); } view.setVisibility( (willBeMerged || ((position + 1) == this.getCount())) ? View.GONE : View.VISIBLE); } View headerLayout = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header); if (null != headerLayout) { String header = headerMessage(position); if (null != header) { View headerLine = convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header_separator); headerLine.setBackgroundColor(mContext.getResources().getColor(R.color.vector_title_color)); TextView headerText = (TextView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header_text); headerText.setTextColor(mContext.getResources().getColor(R.color.vector_title_color)); headerText.setText(header); headerLayout.setVisibility(View.VISIBLE); } else { headerLayout.setVisibility(View.GONE); } } } return isMergedView; }
From source file:im.vector.adapters.VectorMessagesAdapterHelper.java
License:Apache License
/** * Load the avatar image in the avatar view * * @param avatarView the avatar view//from w w w. jav a 2s . c o m * @param row the message row */ void loadMemberAvatar(ImageView avatarView, MessageRow row) { RoomState roomState = row.getRoomState(); Event event = row.getEvent(); RoomMember roomMember = null; if (null != roomState) { roomMember = roomState.getMember(event.getSender()); } String url = null; String displayName = null; // Check whether this avatar url is updated by the current event (This happens in case of new joined member) JsonObject msgContent = event.getContentAsJsonObject(); if (msgContent.has(AVATAR_URL_KEY)) { url = msgContent.get(AVATAR_URL_KEY) == JsonNull.INSTANCE ? null : msgContent.get(AVATAR_URL_KEY).getAsString(); } if (msgContent.has(MEMBERSHIP_KEY)) { String memberShip = msgContent.get(MEMBERSHIP_KEY) == JsonNull.INSTANCE ? null : msgContent.get(MEMBERSHIP_KEY).getAsString(); // the avatar url is the invited one not the inviter one. if (TextUtils.equals(memberShip, RoomMember.MEMBERSHIP_INVITE)) { url = null; if (null != roomMember) { url = roomMember.getAvatarUrl(); } } if (TextUtils.equals(memberShip, RoomMember.MEMBERSHIP_JOIN)) { // in some cases, the displayname cannot be retrieved because the user member joined the room with this event // without being invited (a public room for example) if (msgContent.has(DISPLAYNAME_KEY)) { displayName = msgContent.get(DISPLAYNAME_KEY) == JsonNull.INSTANCE ? null : msgContent.get(DISPLAYNAME_KEY).getAsString(); } } } final String userId = event.getSender(); if (!mSession.isAlive()) { return; } // if there is no preferred display name, use the member one if (TextUtils.isEmpty(displayName) && (null != roomMember)) { displayName = roomMember.displayname; } if ((roomMember != null) && (null == url)) { url = roomMember.getAvatarUrl(); } if (null != roomMember) { VectorUtils.loadUserAvatar(mContext, mSession, avatarView, url, roomMember.getUserId(), displayName); } else { VectorUtils.loadUserAvatar(mContext, mSession, avatarView, url, userId, displayName); } }
From source file:jmm.api.tmdb.TMDBWrapper.java
License:Open Source License
/** * Calls the url and returns the response as a JsonElement, * containing all return parameters in key, value pairs * //from w w w . j av a 2 s. co m * @param tmdbURL the url to open (including all parameters) * @return The JsonElement <br/> null, if there was en error during API call */ protected static JsonElement callAPI(String tmdbURL) { if (tmdbURL == null) { throw new NullPointerException(); } StringBuilder responseBuilder = new StringBuilder(); String line; URLConnection con; BufferedReader br = null; JsonElement root = JsonNull.INSTANCE; try { getConCount().acquire(); con = new URL(tmdbURL).openConnection(); br = new BufferedReader(new InputStreamReader(con.getInputStream(), CHARSET_UTF)); //Solange der Reader bereit zum lesen ist(und das Ende des Dokuments noch nicht erreicht) while ((line = br.readLine()) != null) { responseBuilder.append(line); } root = new JsonParser().parse(responseBuilder.toString()); } catch (JsonSyntaxException | IOException | InterruptedException ex) { String cause = ex.toString().split(":")[0]; if (cause.equals("java.net.UnknownHostException")) { LOG.warn("Please check your internet connectivity."); } else { LOG.error("Error while calling TMDB API: " + escapeAPIKey(ex)); } } finally { //Schliese den Reader if (br != null) { try { br.close(); } catch (IOException ex) { LOG.error("Reader cannot be closed.", ex); } } getConCount().release(); } // System.out.println(responseBuilder.toString()); //Create JsonElement and parse the response String return root; }
From source file:json.tests.parser.JSONDeferredParser.java
License:Open Source License
public JsonElement read(String elementName) { try {/*from w w w .j a v a 2 s .c o m*/ switch (this.reader.peek()) { case STRING: return new JsonPrimitive(this.reader.nextString()); case NUMBER: String number = this.reader.nextString(); return new JsonPrimitive(new LazilyParsedNumber(number)); case BOOLEAN: return new JsonPrimitive(this.reader.nextBoolean()); case NULL: this.reader.nextNull(); return JsonNull.INSTANCE; case BEGIN_ARRAY: JsonArray array = new JsonArray(); this.reader.beginArray(); while (this.reader.hasNext()) { array.add(read(elementName)); } this.reader.endArray(); return array; case BEGIN_OBJECT: if (element.isJsonArray()) { element.getAsJsonArray().get(0); } JsonObject object = new JsonObject(); this.reader.beginObject(); String childName; while (this.reader.hasNext()) { childName = this.reader.nextName(); elementStack.add(childName); object.add(childName, read(elementName)); if (this.found || elementName.equals(childName)) { return object; } } this.reader.endObject(); return object; case END_DOCUMENT: case NAME: case END_OBJECT: case END_ARRAY: default: throw new IllegalArgumentException(); } } catch (IOException e) { e.printStackTrace(); } // we never reach here. Returning null just to make the compiler happy. return null; }
From source file:me.lucko.luckperms.common.utils.gson.JArray.java
License:MIT License
public JArray add(JsonElement value) { if (value == null) { return add(JsonNull.INSTANCE); }//from w w w . j a v a 2 s.c om this.array.add(value); return this; }
From source file:me.lucko.luckperms.common.utils.gson.JArray.java
License:MIT License
public JArray add(String value) { if (value == null) { return add(JsonNull.INSTANCE); }// www. j a va 2 s . c om this.array.add(new JsonPrimitive(value)); return this; }
From source file:me.lucko.luckperms.common.utils.gson.JArray.java
License:MIT License
public JArray add(JElement value) { if (value == null) { return add(JsonNull.INSTANCE); } return add(value.toJson()); }