Example usage for org.json JSONObject optLong

List of usage examples for org.json JSONObject optLong

Introduction

In this page you can find the example usage for org.json JSONObject optLong.

Prototype

public long optLong(String key) 

Source Link

Document

Get an optional long value associated with a key, or zero if there is no such key or if the value is not a number.

Usage

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@SuppressWarnings("deprecation")
public Notification createNotification(Bundle settings, JSONObject obj) {

    // notifications[i] = api.normalizeAPI({
    // 'string': {
    // mandatory: ['title', 'body'],
    // defaults: {'icon':'icon'}
    // },/*  w ww  .  j a v a  2  s .co  m*/
    //
    // 'number': {
    // mandatory: ['id', 'timeMillisSince1970'],
    // // the number of ms after which we start prioritising more recent
    // things above you.
    // defaults: {'epsilon': 1000 * 60 * 24 * 365}
    // },
    //
    // 'boolean': {
    // defaults: {
    // 'vibrate': false,
    // 'sound': false
    // }
    // }

    int icon = settings.getInt("notification_icon", -1);
    if (icon == -1) {
        Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    Notification n = new Notification();
    n.icon = icon;
    n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    long alarmTime = obj.optLong("timeMillisSince1970");
    long displayTime = obj.optLong("displayTimestamp", alarmTime);
    n.when = displayTime;
    n.tickerText = obj.optString("body");
    n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null);

    if (obj.optBoolean("vibrate")) {
        n.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (obj.optBoolean("sound")) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    String uriString = settings.getString("content_uri_prefix");
    if (uriString == null) {
        Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    if (uriString.contains("%d")) {
        uriString = String.format(uriString, obj.optInt("id"));
    }
    Uri uri = Uri.parse(uriString);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(uri);
    n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT);
    return n;
}

From source file:com.fuse.billing.android.Purchase.java

public Purchase(String jsonPurchaseInfo) throws JSONException {
    mOriginalJson = jsonPurchaseInfo;//  w  w w .  ja v  a  2  s.  c o m
    JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mPurchaseState = o.optInt("purchaseState");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mIsAutoRenewing = o.optBoolean("autoRenewing");
    mSignature = o.optString("signature");
    mItemType = o.optString("itemType");
}

From source file:com.vk.sdkweb.api.model.VKApiWikiPage.java

/**
 * Fills a WikiPage instance from JSONObject.
 *//*from  w ww  . ja  va  2  s  . com*/
public VKApiWikiPage parse(JSONObject source) {
    id = source.optInt("id");
    group_id = source.optInt("group_id");
    creator_id = source.optInt("creator_id");
    title = source.optString("title");
    this.source = source.optString("source");
    current_user_can_edit = ParseUtils.parseBoolean(source, "current_user_can_edit");
    current_user_can_edit_access = ParseUtils.parseBoolean(source, "current_user_can_edit_access");
    who_can_view = source.optInt("who_can_view");
    who_can_edit = source.optInt("who_can_edit");
    editor_id = source.optInt("editor_id");
    edited = source.optLong("edited");
    created = source.optLong("created");
    parent = source.optString("parent");
    parent2 = source.optString("parent2");
    return this;
}

From source file:com.vk.sdkweb.api.model.VKApiMessage.java

/**
 * Fills a Message instance from JSONObject.
 *///from ww  w  .jav  a  2s  .  c om
public VKApiMessage parse(JSONObject source) throws JSONException {
    id = source.optInt("id");
    user_id = source.optInt("user_id");
    date = source.optLong("date");
    read_state = ParseUtils.parseBoolean(source, "read_state");
    out = ParseUtils.parseBoolean(source, "out");
    title = source.optString("title");
    body = source.optString("body");
    attachments.fill(source.optJSONArray("attachments"));
    fwd_messages = new VKList<VKApiMessage>(source.optJSONArray("fwd_messages"), VKApiMessage.class);
    emoji = ParseUtils.parseBoolean(source, "emoji");
    deleted = ParseUtils.parseBoolean(source, "deleted");
    return this;
}

From source file:info.axbase.app.VersionInfo.java

public static VersionInfo parse(String text) throws JSONException {
    JSONTokener jsonParser = new JSONTokener(text);
    JSONObject msg = (JSONObject) jsonParser.nextValue();
    if (msg == null) {
        return null;
    }//from w  ww.  ja  v  a  2s .  co  m
    if (msg.optInt("error") == 0) {
        JSONObject data = msg.optJSONObject("data");
        if (data == null) {
            return null;
        }

        VersionInfo versionInfo = new VersionInfo();
        versionInfo.fileName = data.optString("fileName");
        versionInfo.whatsNew = data.optString("whatsNew");
        versionInfo.fileTime = data.optLong("fileTime");
        versionInfo.fileSize = data.optLong("fileSize");
        versionInfo.appProject = data.optString("appProject");
        versionInfo.digest = data.optString("digest");
        versionInfo.version = data.optString("version");
        return versionInfo;
    } else {
        Log.e("ParseError", msg.optString("msg"));
        return null;
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PresenceObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    int presence = obj.optInt(PRESENCE);
    String id = Long.toString(from.id);
    long time = obj.optLong(DbObject.TIMESTAMP);
    ContentValues values = new ContentValues();
    values.put(Contact.PRESENCE, presence);
    values.put(Contact.LAST_PRESENCE_TIME, time);
    context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values,
            "_id=?", new String[] { id });
}

From source file:plugin.google.iap.v3.util.Purchase.java

public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException {
    mItemType = itemType;/*  w  w w. j av a 2s .  c o m*/
    mOriginalJson = jsonPurchaseInfo;
    JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mSignature = signature;

    int state = o.optInt("purchaseState");
    switch (state) {
    case 0:
        mPurchaseState = State.Purchased;
        break;
    case 1:
        mPurchaseState = State.Cancelled;
        break;
    case 2:
        mPurchaseState = State.Refunded;
        break;
    default:
        mPurchaseState = State.Unknown;
    }

}

From source file:ru.rzn.myasoedov.vktest.dto.VKChat.java

@Override
public VKChat parse(JSONObject source) {
    try {/*from w  w  w . j  av a 2s . com*/
        JSONObject message = source.getJSONObject("message");
        int chatId = message.getInt("chat_id");
        super.parse(message);
        id = chatId;
        preview = message.optString("body");
        date = message.optLong("date");
        photoUrl = message.optString("photo_50");
        JSONArray users = message.optJSONArray("chat_active");
        if (users != null) {
            this.users = new int[users.length()];
            for (int i = 0; i < this.users.length; i++) {
                this.users[i] = users.optInt(i);
            }
        }

    } catch (JSONException e) {
        return null;
    }
    return this;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java

@Override
public boolean handleObjFromNetwork(Context context, Contact contact, JSONObject obj) {
    DBHelper helper = new DBHelper(context);
    if (obj.has(DbObjects.TARGET_HASH)) {
        long hashA = obj.optLong(DbObjects.TARGET_HASH);
        long idA = helper.objIdForHash(hashA);

        if (idA == -1) {
            Log.e(TAG, "No objId found for hash " + hashA);
        } else {/*from w w  w .j  a  v  a 2 s .  c  o m*/
            helper.updateParentLastModified(idA);
        }
    }
    return true;
}

From source file:org.angellist.angellistmobile.FeedJSONAdapter.java

@Override
public long getItemId(int position) {
    JSONObject jsonObject = getItem(position);

    return jsonObject.optLong("id");
}