use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.
the class HomeOtherGroupTimeLineDBTask method get.
static MessageListBean get(String accountId, String groupId, int limitCount) {
Gson gson = new Gson();
MessageListBean result = new MessageListBean();
int limit = limitCount > AppConfig.DEFAULT_MSG_COUNT_50 ? limitCount : AppConfig.DEFAULT_MSG_COUNT_50;
List<MessageBean> msgList = new ArrayList<MessageBean>();
String sql = "select * from " + HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME + " where " + HomeOtherGroupTable.HomeOtherGroupDataTable.ACCOUNTID + " = " + accountId + " and " + HomeOtherGroupTable.HomeOtherGroupDataTable.GROUPID + " = " + groupId + " order by " + HomeOtherGroupTable.HomeOtherGroupDataTable.ID + " asc limit " + limit;
Cursor c = getRsd().rawQuery(sql, null);
while (c.moveToNext()) {
String json = c.getString(c.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA));
if (!TextUtils.isEmpty(json)) {
try {
MessageBean value = gson.fromJson(json, MessageBean.class);
if (!value.isMiddleUnreadItem()) {
value.getListViewSpannableString();
}
msgList.add(value);
} catch (JsonSyntaxException e) {
AppLogger.e(e.getMessage());
}
} else {
msgList.add(null);
}
}
//delete the null flag at the head positon and the end position
for (int i = msgList.size() - 1; i >= 0; i--) {
if (msgList.get(i) == null) {
msgList.remove(i);
} else {
break;
}
}
for (int i = 0; i < msgList.size(); i++) {
if (msgList.get(i) == null) {
msgList.remove(i);
} else {
break;
}
}
result.setStatuses(msgList);
c.close();
return result;
}
use of com.google.gson.JsonSyntaxException in project iosched by google.
the class SyncUserCommand method execute.
@Override
public void execute(Context context, String type, String extraData) {
LOGI(TAG, "Received GCM message: " + type);
int syncJitter;
SyncData syncData = null;
if (extraData != null) {
try {
Gson gson = new Gson();
syncData = gson.fromJson(extraData, SyncData.class);
} catch (JsonSyntaxException e) {
LOGI(TAG, "Error while decoding extraData: " + e.toString());
}
}
if (syncData != null && syncData.sync_jitter != 0) {
syncJitter = syncData.sync_jitter;
} else {
syncJitter = DEFAULT_TRIGGER_SYNC_DELAY;
}
scheduleSync(context, syncJitter);
}
use of com.google.gson.JsonSyntaxException in project MusicDNA by harjot-oberai.
the class Genius method search.
public static ArrayList<Lyrics> search(String query) {
ArrayList<Lyrics> results = new ArrayList<>();
query = Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
JsonObject response = null;
try {
URL queryURL = new URL(String.format("http://api.genius.com/search?q=%s", URLEncoder.encode(query, "UTF-8")));
Connection connection = Jsoup.connect(queryURL.toExternalForm()).header("Authorization", "Bearer " + Config.GENIUS).timeout(0).ignoreContentType(true);
Document document = connection.userAgent(Net.USER_AGENT).get();
response = new JsonParser().parse(document.text()).getAsJsonObject();
} catch (JsonSyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (response == null || response.getAsJsonObject("meta").get("status").getAsInt() != 200)
return results;
JsonArray hits = response.getAsJsonObject("response").getAsJsonArray("hits");
int processed = 0;
while (processed < hits.size()) {
JsonObject song = hits.get(processed).getAsJsonObject().getAsJsonObject("result");
String artist = song.getAsJsonObject("primary_artist").get("name").getAsString();
String title = song.get("title").getAsString();
String url = "http://genius.com/songs/" + song.get("id").getAsString();
Lyrics l = new Lyrics(Lyrics.SEARCH_ITEM);
l.setArtist(artist);
l.setTitle(title);
l.setURL(url);
l.setSource("Genius");
results.add(l);
processed++;
}
return results;
}
use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.
the class MyStatusDBTask method getPosition.
private static TimeLinePosition getPosition(String accountId) {
String sql = "select * from " + MyStatusTable.TABLE_NAME + " where " + MyStatusTable.ACCOUNTID + " = " + accountId;
Cursor c = getRsd().rawQuery(sql, null);
Gson gson = new Gson();
while (c.moveToNext()) {
String json = c.getString(c.getColumnIndex(MyStatusTable.TIMELINEDATA));
if (!TextUtils.isEmpty(json)) {
try {
TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
c.close();
return value;
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
}
}
c.close();
return TimeLinePosition.empty();
}
use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.
the class MyStatusDBTask method updatePosition.
private static void updatePosition(TimeLinePosition position, String accountId) {
String sql = "select * from " + MyStatusTable.TABLE_NAME + " where " + MyStatusTable.ACCOUNTID + " = " + accountId;
Cursor c = getRsd().rawQuery(sql, null);
Gson gson = new Gson();
if (c.moveToNext()) {
try {
String[] args = { accountId };
ContentValues cv = new ContentValues();
cv.put(MyStatusTable.TIMELINEDATA, gson.toJson(position));
getWsd().update(MyStatusTable.TABLE_NAME, cv, MyStatusTable.ACCOUNTID + "=?", args);
} catch (JsonSyntaxException e) {
}
} else {
ContentValues cv = new ContentValues();
cv.put(MyStatusTable.ACCOUNTID, accountId);
cv.put(MyStatusTable.TIMELINEDATA, gson.toJson(position));
getWsd().insert(MyStatusTable.TABLE_NAME, MyStatusTable.ID, cv);
}
}
Aggregations