use of com.google.gson.reflect.TypeToken in project Dxditor by kimi2009.
the class MainpageModel method getTestData.
@Override
public void getTestData(final ValueCallBack<List<SbxxBean>> callBack) {
list = new ArrayList<SbxxBean>();
if (Constants.testData) {
list.add(new SbxxBean(0, "", "3"));
list.add(new SbxxBean(1, "", "57"));
list.add(new SbxxBean(2, "", "31"));
callBack.onSuccess(list);
} else {
Request request = new Request.Builder().url(Constants.getAppDeviceStausCount).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String res = response.body().string();
System.out.println("getAppDeviceStausCount:" + res);
try {
JSONObject js = new JSONObject(res);
if (js.getBoolean("success")) {
list = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SbxxBean>>() {
}.getType());
callBack.onSuccess(list);
} else {
callBack.onFail("01");
}
} catch (Exception e) {
callBack.onFail("01");
e.printStackTrace();
}
}
});
}
}
use of com.google.gson.reflect.TypeToken in project Dxditor by kimi2009.
the class MainpageModel method getGjxxData.
@Override
public void getGjxxData(final ValueCallBack<List<GjxxBean>> callBack) {
gjxxList = new ArrayList<GjxxBean>();
if (Constants.testData) {
gjxxList.add(new GjxxBean(1, "已恢复", 11, 0.27f));
gjxxList.add(new GjxxBean(2, "已处理", 19, 0.46f));
gjxxList.add(new GjxxBean(0, "告警中", 11, 0.27f));
callBack.onSuccess(gjxxList);
} else {
Request request = new Request.Builder().url(Constants.getAppDeviceAlarmProportion).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String res = response.body().string();
System.out.println("getAppDeviceAlarmProportion:" + res);
try {
JSONObject js = new JSONObject(res);
if (js.getBoolean("success")) {
gjxxList = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<GjxxBean>>() {
}.getType());
callBack.onSuccess(gjxxList);
} else {
callBack.onFail("01");
}
} catch (Exception e) {
callBack.onFail("01");
e.printStackTrace();
}
}
});
}
}
use of com.google.gson.reflect.TypeToken in project Dxditor by kimi2009.
the class SpzModel method getTrendData.
@Override
public void getTrendData(final ValueCallBack<String> callBack, int position) {
spzTrends = new ArrayList<SpzTrend>();
if (Constants.testData) {
SpzEchartsBean spzBean = new SpzEchartsBean();
if (position == 0) {
for (int i = 0; i < 9; i++) {
spzTrends.add(new SpzTrend(Float.parseFloat("10" + i), "03-2" + i + " 08:00"));
}
} else if (position == 1) {
for (int i = 0; i < 9; i++) {
spzTrends.add(new SpzTrend(Float.parseFloat("8" + i), "03-2" + i + " 08:00"));
}
} else if (position == 2) {
for (int i = 0; i < 9; i++) {
spzTrends.add(new SpzTrend(Float.parseFloat("7" + i), "03-2" + i + " 08:00"));
}
}
List<String> time = new ArrayList<>();
for (int i = 0; i < spzTrends.size(); i++) {
time.add(spzTrends.get(i).getStorageTime());
}
spzBean.xData = time;
List<Float> lineDatas = new ArrayList<>();
for (int i = 0; i < spzTrends.size(); i++) {
lineDatas.add(spzTrends.get(i).getTypeData());
}
spzBean.seriesData = lineDatas;
callBack.onSuccess(gson.toJson(spzBean));
} else {
// Form表单格式的参数传递
FormBody formBody = new FormBody.Builder().add("bridgeCode", spzWarnings.get(position).getBridgeCode()).add("type", spzWarnings.get(position).getType()).add("storageTime", Constants.MONTH).build();
Request request = new Request.Builder().post(formBody).url(Constants.getAppSoundBarrierInfo).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String res = response.body().string();
System.out.println("getAppSoundBarrierInfo:" + res);
try {
JSONObject js = new JSONObject(res);
if (js.getBoolean("success")) {
spzTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SpzTrend>>() {
}.getType());
SpzEchartsBean spzBean = new SpzEchartsBean();
// bridgeBean.initValue =;
List<String> time = new ArrayList<>();
for (int i = 0; i < spzTrends.size(); i++) {
time.add(spzTrends.get(i).getStorageTime());
}
spzBean.xData = time;
List<Float> lineDatas = new ArrayList<>();
for (int i = 0; i < spzTrends.size(); i++) {
lineDatas.add(spzTrends.get(i).getTypeData());
}
spzBean.seriesData = lineDatas;
callBack.onSuccess(gson.toJson(spzBean));
} else {
callBack.onFail("01");
}
} catch (Exception e) {
callBack.onFail("01");
e.printStackTrace();
}
}
});
}
}
use of com.google.gson.reflect.TypeToken in project android-mvp-architecture by MindorksOpenSource.
the class AppDataManager method seedDatabaseOptions.
@Override
public Observable<Boolean> seedDatabaseOptions() {
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
return mDbHelper.isOptionEmpty().concatMap(new Function<Boolean, ObservableSource<? extends Boolean>>() {
@Override
public ObservableSource<? extends Boolean> apply(Boolean isEmpty) throws Exception {
if (isEmpty) {
Type type = new TypeToken<List<Option>>() {
}.getType();
List<Option> optionList = gson.fromJson(CommonUtils.loadJSONFromAsset(mContext, AppConstants.SEED_DATABASE_OPTIONS), type);
return saveOptionList(optionList);
}
return Observable.just(false);
}
});
}
use of com.google.gson.reflect.TypeToken in project Tusky by tuskyapp.
the class SavedTootActivity method delete.
@Override
public void delete(int position, TootEntity item) {
// Delete any media files associated with the status.
ArrayList<String> uris = new Gson().fromJson(item.getUrls(), new TypeToken<ArrayList<String>>() {
}.getType());
if (uris != null) {
for (String uriString : uris) {
Uri uri = Uri.parse(uriString);
if (getContentResolver().delete(uri, null, null) == 0) {
Log.e(TAG, String.format("Did not delete file %s.", uriString));
}
}
}
// update DB
tootDao.delete(item.getUid());
toots.remove(position);
// update adapter
if (adapter != null) {
adapter.removeItem(position);
setNoContent(toots.size());
}
}
Aggregations