use of android.os.AsyncTask in project android_packages_apps_OmniClock by omnirom.
the class AlarmClockFragment method asyncAddAlarm.
private void asyncAddAlarm(final Alarm alarm, final boolean expand) {
final Context context = getActivity().getApplicationContext();
final AsyncTask<Void, Void, AlarmInstance> updateTask = new AsyncTask<Void, Void, AlarmInstance>() {
@Override
protected AlarmInstance doInBackground(Void... parameters) {
if (context != null && alarm != null) {
ContentResolver cr = context.getContentResolver();
// Add alarm to db
Alarm newAlarm = Alarm.addAlarm(cr, alarm);
mScrollToAlarmId = newAlarm.id;
if (expand) {
mExpandedId = newAlarm.id;
}
// Create and add instance to db
if (newAlarm.enabled) {
sDeskClockExtensions.addAlarm(context, newAlarm);
return setupAlarmInstance(context, newAlarm);
}
}
return null;
}
@Override
protected void onPostExecute(AlarmInstance instance) {
if (instance != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean noAlarmSoundHintShown = prefs.getBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, false);
boolean hintShown = prefs.getBoolean(PREF_KEY_ALARM_HINT_SHOWN, false);
if (!instance.mRingtone.equals(Alarm.NO_RINGTONE_URI)) {
Uri defaultAlarm = Utils.getDefaultAlarmUri(getActivity());
if (defaultAlarm == null) {
if (!noAlarmSoundHintShown) {
// show hint that this alarm has been created with alarm tone choosen
AlarmUtils.popNoDefaultAlarmSoundToast(context);
prefs.edit().putBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, true).commit();
return;
}
}
}
if (!hintShown) {
AlarmUtils.popFirstAlarmCreatedToast(context);
prefs.edit().putBoolean(PREF_KEY_ALARM_HINT_SHOWN, true).commit();
} else {
AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
}
}
}
};
updateTask.execute();
}
use of android.os.AsyncTask in project android_packages_apps_OmniClock by omnirom.
the class AlarmClockFragment method asyncDeleteAlarm.
private void asyncDeleteAlarm(final Alarm alarm) {
final Context context = getActivity().getApplicationContext();
final AsyncTask<Void, Void, Void> deleteTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... parameters) {
// Activity may be closed at this point , make sure data is still valid
if (context != null && alarm != null) {
ContentResolver cr = context.getContentResolver();
AlarmStateManager.deleteAllInstances(context, alarm.id);
Alarm.deleteAlarm(cr, alarm.id);
sDeskClockExtensions.deleteAlarm(context, alarm.id);
}
return null;
}
};
mUndoShowing = true;
deleteTask.execute();
}
use of android.os.AsyncTask in project android_packages_apps_OmniClock by omnirom.
the class AlarmClockFragment method asyncUpdateAlarm.
private void asyncUpdateAlarm(final Alarm alarm, final boolean popToast) {
final Context context = getActivity().getApplicationContext();
final AsyncTask<Void, Void, AlarmInstance> updateTask = new AsyncTask<Void, Void, AlarmInstance>() {
@Override
protected AlarmInstance doInBackground(Void... parameters) {
ContentResolver cr = context.getContentResolver();
// Dismiss all old instances
AlarmStateManager.deleteAllInstances(context, alarm.id);
// Update alarm
Alarm.updateAlarm(cr, alarm);
if (alarm.enabled) {
return setupAlarmInstance(context, alarm);
}
return null;
}
@Override
protected void onPostExecute(AlarmInstance instance) {
if (popToast && instance != null) {
AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
}
}
};
updateTask.execute();
}
use of android.os.AsyncTask in project MTweaks-KernelAdiutorMOD by morogoku.
the class BackupFragment method reload.
private void reload() {
if (mLoader == null) {
getHandler().postDelayed(new Runnable() {
@Override
public void run() {
clearItems();
mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
showProgress();
}
@Override
protected List<RecyclerViewItem> doInBackground(Void... voids) {
List<RecyclerViewItem> items = new ArrayList<>();
load(items);
return items;
}
@Override
protected void onPostExecute(List<RecyclerViewItem> items) {
super.onPostExecute(items);
for (RecyclerViewItem item : items) {
addItem(item);
}
hideProgress();
mLoader = null;
}
};
mLoader.execute();
}
}, 250);
}
}
use of android.os.AsyncTask in project MTweaks-KernelAdiutorMOD by morogoku.
the class OnBootFragment method reload.
private void reload() {
if (mLoader == null) {
getHandler().postDelayed(new Runnable() {
@Override
public void run() {
mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
clearItems();
showProgress();
}
@Override
protected List<RecyclerViewItem> doInBackground(Void... voids) {
List<RecyclerViewItem> items = new ArrayList<>();
load(items);
return items;
}
@Override
protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
super.onPostExecute(recyclerViewItems);
for (RecyclerViewItem item : recyclerViewItems) {
addItem(item);
}
hideProgress();
mLoader = null;
}
};
mLoader.execute();
}
}, 250);
}
}
Aggregations