當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonUtils類代碼示例

本文整理匯總了Java中org.matrix.androidsdk.util.JsonUtils的典型用法代碼示例。如果您正苦於以下問題:Java JsonUtils類的具體用法?Java JsonUtils怎麽用?Java JsonUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonUtils類屬於org.matrix.androidsdk.util包,在下文中一共展示了JsonUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listImageMessages

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * @return the imageMessages list
 */
private ArrayList<SlidableImageInfo> listImageMessages() {
    ArrayList<SlidableImageInfo> res = new ArrayList<SlidableImageInfo>();

    for(int position = 0; position < mAdapter.getCount(); position++) {
        MessageRow row = mAdapter.getItem(position);
        Message message = JsonUtils.toMessage(row.getEvent().content);

        if (Message.MSGTYPE_IMAGE.equals(message.msgtype)) {
            ImageMessage imageMessage = (ImageMessage)message;

            SlidableImageInfo info = new SlidableImageInfo();

            info.mImageUrl = imageMessage.url;
            info.mRotationAngle = imageMessage.getRotation();
            info.mOrientation = imageMessage.getOrientation();
            info.mMimeType = imageMessage.getMimeType();
            info.midentifier = row.getEvent().eventId;
            res.add(info);
        }
    }

    return res;
}
 
開發者ID:matrix-org,項目名稱:matrix-android-console,代碼行數:27,代碼來源:ConsoleMessageListFragment.java

示例2: appendEvents

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Filter and append the found events
 *
 * @param events         the matched events list
 * @param eventsToAppend the retrieved events list.
 */
private void appendEvents(ArrayList<Event> events, List<Event> eventsToAppend) {
    // filter
    ArrayList<Event> filteredEvents = new ArrayList<>(eventsToAppend.size());
    for (Event event : eventsToAppend) {
        if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) {
            Message message = JsonUtils.toMessage(event.getContent());

            if (Message.MSGTYPE_FILE.equals(message.msgtype) ||
                    Message.MSGTYPE_IMAGE.equals(message.msgtype) ||
                    Message.MSGTYPE_VIDEO.equals(message.msgtype) ||
                    Message.MSGTYPE_AUDIO.equals(message.msgtype)) {
                filteredEvents.add(event);
            }
        }
    }

    events.addAll(filteredEvents);
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:25,代碼來源:VectorSearchRoomFilesListFragment.java

示例3: isMediaDownloading

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Tells if the downloadId is the media download id.
 *
 * @param event the event
 * @return true if the media is downloading (not the thumbnail)
 */
private boolean isMediaDownloading(Event event) {

    if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
        Message message = JsonUtils.toMessage(event.getContent());

        String url = null;

        if (TextUtils.equals(message.msgtype, Message.MSGTYPE_IMAGE)) {
            url = JsonUtils.toImageMessage(event.getContent()).getUrl();
        } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_VIDEO)) {
            url = JsonUtils.toVideoMessage(event.getContent()).getUrl();
        } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_FILE)) {
            url = JsonUtils.toFileMessage(event.getContent()).getUrl();
        }

        if (!TextUtils.isEmpty(url)) {
            return null != mSession.getMediasCache().downloadIdFromUrl(url);
        }
    }

    return false;
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:29,代碼來源:VectorMessagesAdapterMediasHelper.java

示例4: onScalarEvent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
@JavascriptInterface
public void onScalarEvent(String eventData) {
    Gson gson = JsonUtils.getGson(false);
    final Map<String, Map<String, Object>> objectAsMap;

    try {
        objectAsMap = gson.fromJson(eventData, new TypeToken<Map<String, Map<String, Object>>>() {
        }.getType());
        IntegrationManagerActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.d(LOG_TAG, "onScalarEvent : " + objectAsMap);
                onScalarMessage(objectAsMap);
            }
        });
    } catch (Exception e) {
        Log.e(LOG_TAG, "## onScalarEvent() failed " + e.getMessage());
    }
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:20,代碼來源:IntegrationManagerActivity.java

示例5: sendObjectResponse

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Send an object response
 *
 * @param response  the response
 * @param eventData the modular data
 */
private void sendObjectResponse(Object response, Map<String, Object> eventData) {
    String jsString = null;

    if (null != response) {
        try {
            jsString = "JSON.parse('" + JsonUtils.getGson(false).toJson(response) + "')";
        } catch (Exception e) {
            Log.e(LOG_TAG, "## sendObjectResponse() : toJson failed " + e.getMessage());
        }
    }

    if (null == jsString) {
        jsString = "null";
    }

    sendResponse(jsString, eventData);
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:24,代碼來源:IntegrationManagerActivity.java

示例6: roomTagsWithTagEvent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Extract a list of tags from a room tag event.
 *
 * @param event a room tag event (which can contains several tags)
 * @return a dictionary containing the tags the user defined for one room.
 */
public static HashMap<String, RoomTag> roomTagsWithTagEvent(Event event) {
    HashMap<String, RoomTag> tags = new HashMap<>();

    try {
        RoomTags roomtags = JsonUtils.toRoomTags(event.getContent());

        if ((null != roomtags.tags) && (0 != roomtags.tags.size())) {
            for (String tagName : roomtags.tags.keySet()) {
                HashMap<String, Double> params = roomtags.tags.get(tagName);
                tags.put(tagName, new RoomTag(tagName, params.get("order")));
            }
        }
    } catch (Exception e) {
        Log.d(LOG_TAG, "roomTagsWithTagEvent fails " + e.getMessage());
    }

    return tags;
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:25,代碼來源:RoomTag.java

示例7: managePushRulesUpdate

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Refresh the push rules from the account data events list
 *
 * @param events the account data events.
 */
private void managePushRulesUpdate(List<Map<String, Object>> events) {
    for (Map<String, Object> event : events) {
        String type = (String) event.get("type");

        if (TextUtils.equals(type, "m.push_rules")) {
            if (event.containsKey("content")) {
                Gson gson = new GsonBuilder()
                        .setFieldNamingStrategy(new JsonUtils.MatrixFieldNamingStrategy())
                        .excludeFieldsWithModifiers(Modifier.PRIVATE, Modifier.STATIC)
                        .registerTypeAdapter(Condition.class, new ConditionDeserializer())
                        .create();

                // convert the data to BingRulesResponse
                // because BingRulesManager supports only BingRulesResponse
                JsonElement element = gson.toJsonTree(event.get("content"));
                getBingRulesManager().buildRules(gson.fromJson(element, BingRulesResponse.class));

                // warn the client that the push rules have been updated
                onBingRulesUpdate();
            }

            return;
        }
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:31,代碼來源:MXDataHandler.java

示例8: setClearData

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Update the clear data on this event.
 * This is used after decrypting an event; it should not be used by applications.
 * It fires kMXEventDidDecryptNotification.
 *
 * @param decryptionResult the decryption result, including the plaintext and some key info.
 */
public void setClearData(MXEventDecryptionResult decryptionResult) {
    mClearEvent = null;

    if (null != decryptionResult) {
        if (null != decryptionResult.mClearEvent) {
            mClearEvent = JsonUtils.toEvent(decryptionResult.mClearEvent);
        }

        if (null != mClearEvent) {
            mClearEvent.mSenderCurve25519Key = decryptionResult.mSenderCurve25519Key;
            mClearEvent.mClaimedEd25519Key = decryptionResult.mClaimedEd25519Key;

            if (null != decryptionResult.mForwardingCurve25519KeyChain) {
                mClearEvent.mForwardingCurve25519KeyChain = decryptionResult.mForwardingCurve25519KeyChain;
            } else {
                mClearEvent.mForwardingCurve25519KeyChain = new ArrayList<>();
            }
        }

        mCryptoError = null;
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:30,代碼來源:Event.java

示例9: addCryptoAlgorithm

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Add the crypto algorithm to the room creation parameters.
 *
 * @param algorithm the algorithm
 */
public void addCryptoAlgorithm(String algorithm) {
    if (!TextUtils.isEmpty(algorithm)) {
        Event algoEvent = new Event();
        algoEvent.type = Event.EVENT_TYPE_MESSAGE_ENCRYPTION;

        Map<String, String> contentMap = new HashMap<>();
        contentMap.put("algorithm", algorithm);
        algoEvent.content = JsonUtils.getGson(false).toJsonTree(contentMap);

        if (null == initial_state) {
            initial_state = Arrays.asList(algoEvent);
        } else {
            initial_state.add(algoEvent);
        }
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:22,代碼來源:CreateRoomParams.java

示例10: onRoomKeyRequestEvent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Called when we get an m.room_key_request event
 * This method must be called on getEncryptingThreadHandler() thread.
 *
 * @param event the announcement event.
 */
private void onRoomKeyRequestEvent(final Event event) {
    RoomKeyRequest roomKeyRequest = JsonUtils.toRoomKeyRequest(event.getContentAsJsonObject());

    if (null != roomKeyRequest.action) {
        switch (roomKeyRequest.action) {
            case RoomKeyRequest.ACTION_REQUEST: {
                synchronized (mReceivedRoomKeyRequests) {
                    mReceivedRoomKeyRequests.add(new IncomingRoomKeyRequest(event));
                }
                break;
            }

            case RoomKeyRequest.ACTION_REQUEST_CANCELLATION: {
                synchronized (mReceivedRoomKeyRequestCancellations) {
                    mReceivedRoomKeyRequestCancellations.add(new IncomingRoomKeyRequestCancellation(event));
                }
                break;
            }

            default:
                Log.e(LOG_TAG, "## onRoomKeyRequestEvent() : unsupported action " + roomKeyRequest.action);
        }
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:31,代碼來源:MXCrypto.java

示例11: onLiveEvent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
@Override
public void onLiveEvent(final Event event, RoomState roomState) {
    uiThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
                RoomMember member = JsonUtils.toRoomMember(event.content);
                User user = mSession.getDataHandler().getStore().getUser(member.getUserId());

                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
                boolean displayLeftMembers = preferences.getBoolean(getString(R.string.settings_key_display_left_members), false);

                if (member.hasLeft() && !displayLeftMembers) {
                    mAdapter.deleteUser(user);
                    mAdapter.remove(member);
                    mAdapter.notifyDataSetChanged();
                } else {
                    // the user can be a new one
                    boolean mustResort = mAdapter.saveUser(user);
                    mAdapter.updateMember(event.stateKey, JsonUtils.toRoomMember(event.content));

                    if (mustResort) {
                        mAdapter.sortMembers();
                        mAdapter.notifyDataSetChanged();
                    }
                }
            } else if (Event.EVENT_TYPE_STATE_ROOM_POWER_LEVELS.equals(event.type)) {
                mAdapter.setPowerLevels(JsonUtils.toPowerLevels(event.content));
            }
        }
    });
}
 
開發者ID:matrix-org,項目名稱:matrix-android-console,代碼行數:33,代碼來源:RoomMembersDialogFragment.java

示例12: toWidgetContent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Convert a json object into a WidgetContent instance
 * @param jsonObject
 * @return
 */
public static WidgetContent toWidgetContent(JsonElement jsonObject) {
    try {
        return JsonUtils.getGson(false).fromJson(jsonObject, WidgetContent.class);
    } catch (Exception e) {
        Log.e(LOG_TAG, "## toWidgetContent() : failed " + e.getMessage());
    }

    return new WidgetContent();
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:15,代碼來源:WidgetContent.java

示例13: getObjectAsJsonMap

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Convert an object to a map
 *
 * @param object the object to convert
 * @return the event as a map
 */
private static Map<String, Object> getObjectAsJsonMap(Object object) {
    Gson gson = JsonUtils.getGson(false);
    Map<String, Object> objectAsMap = null;

    try {
        String stringifiedEvent = gson.toJson(object);
        objectAsMap = gson.fromJson(stringifiedEvent, new TypeToken<HashMap<String, Object>>() {
        }.getType());
    } catch (Exception e) {
        Log.e(LOG_TAG, "## getObjectAsJsonMap() failed " + e.getMessage());
    }

    return objectAsMap;
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:21,代碼來源:IntegrationManagerActivity.java

示例14: RoomMediaMessage

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Constructor from an event.
 *
 * @param event the event
 */
public RoomMediaMessage(Event event) {
    setEvent(event);

    Message message = JsonUtils.toMessage(event.getContent());
    if (null != message) {
        setMessageType(message.msgtype);
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:14,代碼來源:RoomMediaMessage.java

示例15: handlePresenceEvent

import org.matrix.androidsdk.util.JsonUtils; //導入依賴的package包/類
/**
 * Handle a presence event.
 *
 * @param presenceEvent teh presence event.
 */
private void handlePresenceEvent(Event presenceEvent) {
    // Presence event
    if (Event.EVENT_TYPE_PRESENCE.equals(presenceEvent.getType())) {
        User userPresence = JsonUtils.toUser(presenceEvent.getContent());

        // use the sender by default
        if (!TextUtils.isEmpty(presenceEvent.getSender())) {
            userPresence.user_id = presenceEvent.getSender();
        }

        User user = mStore.getUser(userPresence.user_id);

        if (user == null) {
            user = userPresence;
            user.setDataHandler(this);
        } else {
            user.currently_active = userPresence.currently_active;
            user.presence = userPresence.presence;
            user.lastActiveAgo = userPresence.lastActiveAgo;
        }

        user.setLatestPresenceTs(System.currentTimeMillis());

        // check if the current user has been updated
        if (mCredentials.userId.equals(user.user_id)) {
            // always use the up-to-date information
            getMyUser().displayname = user.displayname;
            getMyUser().avatar_url = user.getAvatarUrl();

            mStore.setAvatarURL(user.getAvatarUrl(), presenceEvent.getOriginServerTs());
            mStore.setDisplayName(user.displayname, presenceEvent.getOriginServerTs());
        }

        mStore.storeUser(user);
        this.onPresenceUpdate(presenceEvent, user);
    }
}
 
開發者ID:matrix-org,項目名稱:matrix-android-sdk,代碼行數:43,代碼來源:MXDataHandler.java


注:本文中的org.matrix.androidsdk.util.JsonUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。