use of android.os.AsyncTask in project android_packages_apps_Settings by DirtyUnicorns.
the class NotificationSoundPreference method updateRingtoneName.
private void updateRingtoneName(final Uri uri) {
AsyncTask ringtoneNameTask = new AsyncTask<Object, Void, CharSequence>() {
@Override
protected CharSequence doInBackground(Object... params) {
if (uri == null) {
return getContext().getString(com.android.internal.R.string.ringtone_silent);
} else if (RingtoneManager.isDefault(uri)) {
return getContext().getString(R.string.notification_sound_default);
} else if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())) {
return getContext().getString(R.string.notification_unknown_sound_title);
} else {
return Ringtone.getTitle(getContext(), uri, false, /* followSettingsUri */
true);
}
}
@Override
protected void onPostExecute(CharSequence name) {
setSummary(name);
}
};
ringtoneNameTask.execute();
}
use of android.os.AsyncTask 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 android.os.AsyncTask 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);
}
use of android.os.AsyncTask in project keepass2android by PhilippC.
the class GoogleDriveFileStorage method initializeAccountOrPath.
private void initializeAccountOrPath(final JavaFileStorage.FileStorageSetupActivity setupAct, final String accountNameOrPath) {
final Activity activity = ((Activity) setupAct);
final Context appContext = activity.getApplicationContext();
String accountNameTemp;
GDrivePath gdrivePath = null;
if (accountNameOrPath.startsWith(getProtocolPrefix())) {
gdrivePath = new GDrivePath();
// don't verify yet, we're not yet initialized:
try {
gdrivePath.setPathWithoutVerify(accountNameOrPath);
} catch (Exception e) {
finishWithError(setupAct, e);
}
accountNameTemp = gdrivePath.getAccount();
} else
accountNameTemp = accountNameOrPath;
final String accountName = accountNameTemp;
AsyncTask<Object, Void, AsyncTaskResult<String>> task = new AsyncTask<Object, Void, AsyncTaskResult<String>>() {
@Override
protected AsyncTaskResult<String> doInBackground(Object... arg0) {
try {
initializeAccount(appContext, accountName);
if (setupAct.getProcessName().equals(PROCESS_NAME_SELECTFILE))
setupAct.getState().putString(EXTRA_PATH, getRootPathForAccount(accountName));
return new AsyncTaskResult<String>("ok");
} catch (Exception anyError) {
return new AsyncTaskResult<String>(anyError);
}
}
@Override
protected void onPostExecute(AsyncTaskResult<String> result) {
Exception error = result.getError();
if (error != null) {
if (UserRecoverableAuthIOException.class.isAssignableFrom(error.getClass())) {
mAccountData.remove(accountName);
activity.startActivityForResult(((UserRecoverableAuthIOException) error).getIntent(), REQUEST_AUTHORIZATION);
} else {
finishWithError(setupAct, error);
}
} else if (isCancelled()) {
// cancel handling here
logDebug("Async Task cancelled!");
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
} else {
// all right!
finishActivityWithSuccess(setupAct);
}
}
};
task.execute(new Object[] {});
}
use of android.os.AsyncTask in project keepass2android by PhilippC.
the class OneDriveStorage method onStart.
@Override
public void onStart(final FileStorageSetupActivity activity) {
Log.d("KP2AJ", "onStart");
if (activity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
activity.getState().putString(EXTRA_PATH, activity.getPath());
JavaFileStorage.FileStorageSetupActivity storageSetupAct = activity;
if (oneDriveClient != null) {
Log.d("KP2AJ", "auth successful");
try {
finishActivityWithSuccess(activity);
return;
} catch (Exception e) {
Log.d("KP2AJ", "finish with error: " + e.toString());
finishWithError(activity, e);
return;
}
}
{
Log.d("KP2AJ", "Starting auth");
new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
try {
return buildClient((Activity) activity);
} catch (Exception e) {
return null;
}
}
@Override
protected void onPostExecute(Object o) {
if (o == null) {
Log.i(TAG, "authenticating not successful");
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, "authenticating not succesful");
((Activity) activity).setResult(Activity.RESULT_CANCELED, data);
((Activity) activity).finish();
} else {
Log.i(TAG, "authenticating successful");
oneDriveClient = (IOneDriveClient) o;
finishActivityWithSuccess(activity);
}
}
}.execute();
}
}
Aggregations