use of com.google.gson.JsonElement in project PneumaticCraft by MineMaarten.
the class ProgWidgetConfig method readFromJson.
@Override
protected void readFromJson(JsonObject json) {
JsonArray array = json.get("blacklist").getAsJsonArray();
blacklistedPieces.clear();
for (JsonElement element : array) {
blacklistedPieces.add(element.getAsString());
}
}
use of com.google.gson.JsonElement in project PneumaticCraft by MineMaarten.
the class JsonToNBTConverter method getTag.
private NBTTagCompound getTag(JsonObject object) {
NBTTagCompound nbt = new NBTTagCompound();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
JsonObject keyObject = entry.getValue().getAsJsonObject();
int type = keyObject.get("type").getAsInt();
JsonElement element = keyObject.get("value");
switch(type) {
case 1:
nbt.setByte(entry.getKey(), (byte) element.getAsDouble());
break;
case 2:
nbt.setShort(entry.getKey(), (short) element.getAsDouble());
case 3:
nbt.setInteger(entry.getKey(), (int) element.getAsDouble());
break;
case 4:
nbt.setLong(entry.getKey(), (long) element.getAsDouble());
break;
case 5:
nbt.setFloat(entry.getKey(), (float) element.getAsDouble());
break;
case 6:
nbt.setDouble(entry.getKey(), element.getAsDouble());
break;
// break;
case 8:
nbt.setString(entry.getKey(), element.getAsString());
break;
case 9:
JsonArray array = element.getAsJsonArray();
NBTTagList tagList = new NBTTagList();
for (JsonElement e : array) {
tagList.appendTag(getTag(e.getAsJsonObject()));
}
nbt.setTag(entry.getKey(), tagList);
break;
case 10:
nbt.setTag(entry.getKey(), getTag(element.getAsJsonObject()));
break;
case 11:
array = element.getAsJsonArray();
int[] intArray = new int[array.size()];
for (int i = 0; i < array.size(); i++) {
intArray[i] = array.get(i).getAsInt();
}
nbt.setTag(entry.getKey(), new NBTTagIntArray(intArray));
break;
default:
throw new IllegalArgumentException("NBT type no " + type + " is not supported by the Json to NBT converter!");
}
}
return nbt;
}
use of com.google.gson.JsonElement in project MinecraftForge by MinecraftForge.
the class MetadataCollection method from.
public static MetadataCollection from(@Nullable InputStream inputStream, String sourceName) {
if (inputStream == null) {
return new MetadataCollection();
}
InputStreamReader reader = new InputStreamReader(inputStream);
try {
MetadataCollection collection;
Gson gson = new GsonBuilder().registerTypeAdapter(ArtifactVersion.class, new ArtifactVersionAdapter()).create();
JsonParser parser = new JsonParser();
JsonElement rootElement = parser.parse(reader);
if (rootElement.isJsonArray()) {
collection = new MetadataCollection();
JsonArray jsonList = rootElement.getAsJsonArray();
collection.modList = new ModMetadata[jsonList.size()];
int i = 0;
for (JsonElement mod : jsonList) {
collection.modList[i++] = gson.fromJson(mod, ModMetadata.class);
}
} else {
collection = gson.fromJson(rootElement, MetadataCollection.class);
}
collection.parseModMetadataList();
return collection;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "The mcmod.info file in %s cannot be parsed as valid JSON. It will be ignored", sourceName);
return new MetadataCollection();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.google.gson.JsonElement in project remusic by aa112901.
the class MoreFragment method setClick.
private void setClick() {
if (muaicflowAdapter != null) {
muaicflowAdapter.setOnItemClickListener(new MusicFlowAdapter.OnRecyclerViewItemClickListener() {
@Override
public void onItemClick(View view, String data) {
switch(Integer.parseInt(data)) {
case 0:
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (adapterMusicInfo.songId == MusicPlayer.getCurrentAudioId())
return;
long[] ids = new long[1];
ids[0] = adapterMusicInfo.songId;
HashMap<Long, MusicInfo> map = new HashMap<Long, MusicInfo>();
map.put(ids[0], adapterMusicInfo);
MusicPlayer.playNext(mContext, map, ids);
}
}, 100);
dismiss();
break;
case 1:
ArrayList<MusicInfo> musicList = new ArrayList<MusicInfo>();
musicList.add(adapterMusicInfo);
AddNetPlaylistDialog.newInstance(musicList).show(getFragmentManager(), "add");
dismiss();
break;
case 2:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + adapterMusicInfo.data));
shareIntent.setType("audio/*");
mContext.startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
dismiss();
break;
case 3:
new AlertDialog.Builder(mContext).setTitle(getResources().getString(R.string.sure_to_delete_music)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, adapterMusicInfo.songId);
mContext.getContentResolver().delete(uri, null, null);
if (MusicPlayer.getCurrentAudioId() == adapterMusicInfo.songId) {
if (MusicPlayer.getQueueSize() == 0) {
MusicPlayer.stop();
} else {
MusicPlayer.next();
}
}
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
PlaylistsManager.getInstance(mContext).deleteMusic(mContext, adapterMusicInfo.songId);
mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
}
}, 200);
} catch (Exception e) {
e.printStackTrace();
}
dismiss();
}
}).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
}).show();
dismiss();
break;
case 4:
if (adapterMusicInfo.islocal) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<SearchArtistInfo> artistResults = new ArrayList<>();
try {
JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.artist, 1, 50)).get("result").getAsJsonObject();
JsonObject artistObject = jsonObject.get("artist_info").getAsJsonObject();
JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
for (JsonElement o : artistArray) {
SearchArtistInfo artistInfo = MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
artistResults.add(artistInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
if (artistResults.size() == 0) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "没有找到该艺术家", Toast.LENGTH_SHORT).show();
}
});
} else {
SearchArtistInfo info = artistResults.get(0);
Intent intent = new Intent(mContext, ArtistDetailActivity.class);
intent.putExtra("artistid", info.getArtist_id());
intent.putExtra("artistname", info.getAuthor());
mContext.startActivity(intent);
}
return null;
}
}.execute();
} else {
Intent intent = new Intent(mContext, ArtistDetailActivity.class);
intent.putExtra("artistid", adapterMusicInfo.artistId + "");
intent.putExtra("artistname", adapterMusicInfo.artist);
mContext.startActivity(intent);
}
dismiss();
break;
case 5:
if (adapterMusicInfo.islocal) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<SearchAlbumInfo> albumResults = new ArrayList<SearchAlbumInfo>();
try {
JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.albumName, 1, 10)).get("result").getAsJsonObject();
JsonObject albumObject = jsonObject.get("album_info").getAsJsonObject();
JsonArray albumArray = albumObject.get("album_list").getAsJsonArray();
for (JsonElement o : albumArray) {
SearchAlbumInfo albumInfo = MainApplication.gsonInstance().fromJson(o, SearchAlbumInfo.class);
albumResults.add(albumInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
if (albumResults.size() == 0) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "没有找到所属专辑", Toast.LENGTH_SHORT).show();
}
});
} else {
SearchAlbumInfo info = albumResults.get(0);
Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
intent.putExtra("albumid", info.getAlbum_id());
intent.putExtra("albumart", info.getPic_small());
intent.putExtra("albumname", info.getTitle());
intent.putExtra("albumdetail", info.getAlbum_desc());
mContext.startActivity(intent);
}
return null;
}
};
} else {
Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
intent.putExtra("albumid", adapterMusicInfo.albumId + "");
intent.putExtra("albumart", adapterMusicInfo.albumData);
intent.putExtra("albumname", adapterMusicInfo.albumName);
mContext.startActivity(intent);
}
dismiss();
break;
case 6:
if (adapterMusicInfo.islocal) {
new AlertDialog.Builder(mContext).setTitle(getResources().getString(R.string.sure_to_set_ringtone)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri ringUri = Uri.parse("file://" + adapterMusicInfo.data);
RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_NOTIFICATION, ringUri);
dialog.dismiss();
Toast.makeText(mContext, getResources().getString(R.string.set_ringtone_successed), Toast.LENGTH_SHORT).show();
dismiss();
}
}).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
} else {
}
break;
case 7:
MusicDetailFragment detailFrament = MusicDetailFragment.newInstance(adapterMusicInfo);
detailFrament.show(getActivity().getSupportFragmentManager(), "detail");
dismiss();
break;
default:
break;
}
}
});
recyclerView.setAdapter(muaicflowAdapter);
return;
}
commonAdapter.setOnItemClickListener(new OverFlowAdapter.OnRecyclerViewItemClickListener() {
@Override
public void onItemClick(View view, String data) {
switch(Integer.parseInt(data)) {
case 0:
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
HashMap<Long, MusicInfo> infos = new HashMap<Long, MusicInfo>();
int len = list.size();
long[] listid = new long[len];
for (int i = 0; i < len; i++) {
MusicInfo info = list.get(i);
listid[i] = info.songId;
infos.put(listid[i], info);
}
MusicPlayer.playAll(infos, listid, 0, false);
}
}, 60);
dismiss();
break;
case 1:
AddNetPlaylistDialog.newInstance(list).show(getFragmentManager(), "add");
dismiss();
break;
case 2:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
for (MusicInfo music : list) {
if (MusicPlayer.getCurrentAudioId() == music.songId) {
if (MusicPlayer.getQueueSize() == 0) {
MusicPlayer.stop();
} else {
MusicPlayer.next();
}
}
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, music.songId);
mContext.getContentResolver().delete(uri, null, null);
PlaylistsManager.getInstance(mContext).deleteMusic(mContext, music.songId);
}
return null;
}
@Override
protected void onPostExecute(Void v) {
mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
}
}.execute();
// Handler handler1 = new Handler();
// handler1.postDelayed(new Runnable() {
// @Override
// public void run() {
// for (final MusicInfo music : list) {
// PlaylistsManager.getInstance(mContext).deleteMusic(mContext, music.songId);
// }
// }
// }, 100);
// file = new File(music.data);
// if (file.exists())
// file.delete();
// if (file.exists() == false) {
// mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
// Uri.parse("file://" + music.data)));
// }
// HandlerUtil.CommonHandler handler1 = new HandlerUtil.CommonHandler(mContext);
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
// }
// }, 600);
dismiss();
break;
}
}
});
recyclerView.setAdapter(commonAdapter);
}
use of com.google.gson.JsonElement in project remusic by aa112901.
the class NetMoreFragment method setClick.
private void setClick() {
muaicflowAdapter.setOnItemClickListener(new MusicFlowAdapter.OnRecyclerViewItemClickListener() {
@Override
public void onItemClick(View view, String data) {
switch(Integer.parseInt(data)) {
case 0:
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (adapterMusicInfo.songId == MusicPlayer.getCurrentAudioId())
return;
long[] ids = new long[1];
ids[0] = adapterMusicInfo.songId;
HashMap<Long, MusicInfo> map = new HashMap<Long, MusicInfo>();
map.put(ids[0], adapterMusicInfo);
MusicPlayer.playNext(mContext, map, ids);
}
}, 100);
dismiss();
break;
case 1:
final ArrayList<MusicInfo> musicList = new ArrayList<MusicInfo>();
musicList.add(adapterMusicInfo);
AddNetPlaylistDialog.newInstance(musicList).show(getFragmentManager(), "add");
dismiss();
break;
case 2:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + adapterMusicInfo.data));
shareIntent.setType("audio/*");
mContext.startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
dismiss();
break;
case 3:
new AlertDialog.Builder(mContext).setTitle("要下载音乐吗").setPositiveButton(mContext.getString(R.string.sure), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Down.downMusic(MainApplication.context, adapterMusicInfo.songId + "", adapterMusicInfo.musicName, adapterMusicInfo.artist);
dialog.dismiss();
}
}).setNegativeButton(mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
dismiss();
break;
case 4:
if (adapterMusicInfo.islocal) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<SearchArtistInfo> artistResults = new ArrayList<>();
try {
JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.artist, 1, 50)).get("result").getAsJsonObject();
JsonObject artistObject = jsonObject.get("artist_info").getAsJsonObject();
JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
for (JsonElement o : artistArray) {
SearchArtistInfo artistInfo = MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
artistResults.add(artistInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
if (artistResults.size() == 0) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "没有找到该艺术家", Toast.LENGTH_SHORT).show();
}
});
} else {
SearchArtistInfo info = artistResults.get(0);
Intent intent = new Intent(mContext, ArtistDetailActivity.class);
intent.putExtra("artistid", info.getArtist_id());
intent.putExtra("artistname", info.getAuthor());
// intent.putExtra("albumid", info.getAlbum_id());
// intent.putExtra("albumart", info.getPic_small());
// intent.putExtra("albumname", info.getTitle());
// intent.putExtra("albumdetail",info.getAlbum_desc());
mContext.startActivity(intent);
}
return null;
}
}.execute();
} else {
Intent intent = new Intent(mContext, ArtistDetailActivity.class);
intent.putExtra("artistid", adapterMusicInfo.artistId + "");
intent.putExtra("artistname", adapterMusicInfo.artist);
mContext.startActivity(intent);
}
dismiss();
break;
case 5:
if (adapterMusicInfo.islocal) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<SearchAlbumInfo> albumResults = new ArrayList<SearchAlbumInfo>();
try {
JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.albumName, 1, 10)).get("result").getAsJsonObject();
// JsonObject artistObject = jsonObject.get("artist_info").getAsJsonObject();
// JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
// for (JsonElement o : artistArray) {
// SearchArtistInfo artistInfo = MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
// artistResults.add(artistInfo);
// }
Log.e("search", jsonObject.toString());
JsonObject albumObject = jsonObject.get("album_info").getAsJsonObject();
JsonArray albumArray = albumObject.get("album_list").getAsJsonArray();
for (JsonElement o : albumArray) {
SearchAlbumInfo albumInfo = MainApplication.gsonInstance().fromJson(o, SearchAlbumInfo.class);
albumResults.add(albumInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
if (albumResults.size() == 0) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "没有找到所属专辑", Toast.LENGTH_SHORT).show();
}
});
} else {
SearchAlbumInfo info = albumResults.get(0);
Log.e("search", info.getAlbum_id() + " " + info.getTitle());
Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
intent.putExtra("albumid", info.getAlbum_id());
intent.putExtra("albumart", info.getPic_small());
intent.putExtra("albumname", info.getTitle());
intent.putExtra("albumdetail", info.getAlbum_desc());
mContext.startActivity(intent);
}
return null;
}
}.execute();
} else {
Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
intent.putExtra("albumid", adapterMusicInfo.albumId + "");
intent.putExtra("albumart", adapterMusicInfo.albumData);
intent.putExtra("albumname", adapterMusicInfo.albumName);
mContext.startActivity(intent);
}
dismiss();
break;
case 6:
MusicDetailFragment detailFrament = MusicDetailFragment.newInstance(adapterMusicInfo);
detailFrament.show(getActivity().getSupportFragmentManager(), "detail");
dismiss();
break;
default:
break;
}
}
});
recyclerView.setAdapter(muaicflowAdapter);
}
Aggregations