use of android.os.AsyncTask in project Slide by ccrama.
the class PopulateShadowboxInfo method doActionbar.
public static void doActionbar(final CommentNode node, final View rootView, final Activity c, boolean extras) {
final Comment s = node.getComment();
TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title);
TextView desc = (TextView) rootView.findViewById(R.id.desc);
String distingush = "";
if (s != null) {
if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR)
distingush = "[M]";
else if (s.getDistinguishedStatus() == DistinguishedStatus.ADMIN)
distingush = "[A]";
SpannableStringBuilder commentTitle = new SpannableStringBuilder();
SpannableStringBuilder level = new SpannableStringBuilder();
if (!node.isTopLevel()) {
level.append("[" + node.getDepth() + "] ");
level.setSpan(new RelativeSizeSpan(0.7f), 0, level.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
commentTitle.append(level);
}
commentTitle.append(Html.fromHtml(s.getDataNode().get("body_html").asText().trim()));
title.setTextHtml(commentTitle);
title.setMaxLines(3);
String spacer = c.getString(R.string.submission_properties_seperator);
SpannableStringBuilder titleString = new SpannableStringBuilder();
SpannableStringBuilder author = new SpannableStringBuilder(" /u/" + s.getAuthor() + " ");
int authorcolor = Palette.getFontColorUser(s.getAuthor());
if (Authentication.name != null && s.getAuthor().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR || s.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_green_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (authorcolor != 0) {
author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
titleString.append(author);
titleString.append(distingush);
titleString.append(spacer);
titleString.append(TimeUtils.getTimeAgo(s.getCreated().getTime(), c));
desc.setText(titleString);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
if (extras) {
final ImageView downvotebutton = (ImageView) rootView.findViewById(R.id.downvote);
final ImageView upvotebutton = (ImageView) rootView.findViewById(R.id.upvote);
if (s.isArchived()) {
downvotebutton.setVisibility(View.GONE);
upvotebutton.setVisibility(View.GONE);
} else if (Authentication.isLoggedIn && Authentication.didOnline) {
if (SettingValues.actionbarVisible && downvotebutton.getVisibility() != View.VISIBLE) {
downvotebutton.setVisibility(View.VISIBLE);
upvotebutton.setVisibility(View.VISIBLE);
}
switch(ActionStates.getVoteDirection(s)) {
case UPVOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : 1))));
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
case DOWNVOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : -1))));
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
case NO_VOTE:
{
((TextView) rootView.findViewById(R.id.score)).setTextColor(((TextView) rootView.findViewById(R.id.comments)).getCurrentTextColor());
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
break;
}
}
}
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (ActionStates.isSaved(s)) {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
} else {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
rootView.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
if (ActionStates.isSaved(s)) {
new AccountManager(Authentication.reddit).unsave(s);
ActionStates.setSaved(s, false);
} else {
new AccountManager(Authentication.reddit).save(s);
ActionStates.setSaved(s, true);
}
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.isSaved(s)) {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, rootView.findViewById(R.id.save), ContextCompat.getColor(c, R.color.md_amber_500));
} else {
((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
}
if (!Authentication.isLoggedIn || !Authentication.didOnline) {
rootView.findViewById(R.id.save).setVisibility(View.GONE);
}
try {
final TextView points = ((TextView) rootView.findViewById(R.id.score));
final TextView comments = ((TextView) rootView.findViewById(R.id.comments));
if (Authentication.isLoggedIn && Authentication.didOnline) {
{
downvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.getVoteDirection(s) != VoteDirection.DOWNVOTE) {
// has not been downvoted
points.setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, downvotebutton, ContextCompat.getColor(c, R.color.md_blue_500));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
// if a post is at 0 votes, keep it at 0 when downvoting
final int downvoteScore = (s.getScore() == 0) ? 0 : s.getScore() - 1;
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", downvoteScore));
new Vote(false, points, c).execute(s);
ActionStates.setVoteDirection(s, VoteDirection.DOWNVOTE);
} else {
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, c).execute(s);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
});
}
{
upvotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
if (ActionStates.getVoteDirection(s) != VoteDirection.UPVOTE) {
// has not been upvoted
points.setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
AnimateHelper.setFlashAnimation(rootView, upvotebutton, ContextCompat.getColor(c, R.color.md_orange_500));
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore() + 1));
new Vote(true, points, c).execute(s);
ActionStates.setVoteDirection(s, VoteDirection.UPVOTE);
} else {
points.setTextColor(comments.getCurrentTextColor());
new Vote(points, c).execute(s);
((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
});
}
} else {
upvotebutton.setVisibility(View.GONE);
downvotebutton.setVisibility(View.GONE);
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}
}
use of android.os.AsyncTask in project Slide by ccrama.
the class PopulateSubmissionViewHolder method showBan.
public void showBan(final Context mContext, final View mToolbar, final Submission submission, String rs, String nt, String msg, String t) {
LinearLayout l = new LinearLayout(mContext);
l.setOrientation(LinearLayout.VERTICAL);
int sixteen = Reddit.dpToPxVertical(16);
l.setPadding(sixteen, 0, sixteen, 0);
final EditText reason = new EditText(mContext);
reason.setHint(R.string.mod_ban_reason);
reason.setText(rs);
reason.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(reason);
final EditText note = new EditText(mContext);
note.setHint(R.string.mod_ban_note_mod);
note.setText(nt);
note.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(note);
final EditText message = new EditText(mContext);
message.setHint(R.string.mod_ban_note_user);
message.setText(msg);
message.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
l.addView(message);
final EditText time = new EditText(mContext);
time.setHint(R.string.mod_ban_time);
time.setText(t);
time.setInputType(InputType.TYPE_CLASS_NUMBER);
l.addView(time);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
builder.setView(l).setTitle(mContext.getString(R.string.mod_ban_title, submission.getAuthor())).setCancelable(true).setPositiveButton(R.string.mod_btn_ban, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// to ban
if (reason.getText().toString().isEmpty()) {
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_reason_required).setMessage(R.string.misc_please_try_again).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
}
}).setCancelable(false).show();
} else {
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
try {
String n = note.getText().toString();
String m = message.getText().toString();
if (n.isEmpty()) {
n = null;
}
if (m.isEmpty()) {
m = null;
}
if (time.getText().toString().isEmpty()) {
new ModerationManager(Authentication.reddit).banUserPermanently(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m);
} else {
new ModerationManager(Authentication.reddit).banUser(submission.getSubredditName(), submission.getAuthor(), reason.getText().toString(), n, m, Integer.valueOf(time.getText().toString()));
}
return true;
} catch (Exception e) {
if (e instanceof InvalidScopeException) {
scope = true;
}
e.printStackTrace();
return false;
}
}
boolean scope;
@Override
protected void onPostExecute(Boolean done) {
Snackbar s;
if (done) {
s = Snackbar.make(mToolbar, R.string.mod_ban_success, Snackbar.LENGTH_SHORT);
} else {
if (scope) {
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_ban_reauth).setMessage(R.string.mod_ban_reauth_question).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(mContext, Reauthenticate.class);
mContext.startActivity(i);
}
}).setNegativeButton(R.string.misc_maybe_later, null).setCancelable(false).show();
}
s = Snackbar.make(mToolbar, R.string.mod_ban_fail, Snackbar.LENGTH_INDEFINITE).setAction(R.string.misc_try_again, new View.OnClickListener() {
@Override
public void onClick(View v) {
showBan(mContext, mToolbar, submission, reason.getText().toString(), note.getText().toString(), message.getText().toString(), time.getText().toString());
}
});
}
if (s != null) {
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}).setNegativeButton(R.string.btn_cancel, null).show();
}
use of android.os.AsyncTask in project Slide by ccrama.
the class PopulateSubmissionViewHolder method showModBottomSheet.
public <T extends Contribution> void showModBottomSheet(final Activity mContext, final Submission submission, final List<T> posts, final SubmissionViewHolder holder, final RecyclerView recyclerview, final Map<String, Integer> reports, final Map<String, String> reports2) {
final Resources res = mContext.getResources();
int[] attrs = new int[] { R.attr.tintColor };
TypedArray ta = mContext.obtainStyledAttributes(attrs);
int color = ta.getColor(0, Color.WHITE);
Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.profile, null);
final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.report, null);
final Drawable approve = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.support, null);
final Drawable nsfw = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null);
final Drawable spoiler = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.spoil, null);
final Drawable pin = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.sub, null);
final Drawable lock = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.lock, null);
final Drawable flair = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_format_quote_white_48dp, null);
final Drawable remove = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.close, null);
final Drawable remove_reason = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.reportreason, null);
final Drawable ban = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ban, null);
final Drawable spam = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.spam, null);
final Drawable distinguish = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null);
profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
approve.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
spam.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
nsfw.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
pin.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
flair.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
remove.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
spoiler.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
remove_reason.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ban.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
spam.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
distinguish.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
lock.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
ta.recycle();
BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
int reportCount = reports.size() + reports2.size();
b.sheet(0, report, res.getQuantityString(R.plurals.mod_btn_reports, reportCount, reportCount));
boolean approved = false;
String whoApproved = "";
b.sheet(1, approve, res.getString(R.string.mod_btn_approve));
b.sheet(6, remove, mContext.getString(R.string.mod_btn_remove)).sheet(7, remove_reason, res.getString(R.string.mod_btn_remove_reason)).sheet(30, spam, "Mark as spam");
// b.sheet(2, spam, mContext.getString(R.string.mod_btn_spam)) todo this
b.sheet(20, flair, res.getString(R.string.mod_btn_submission_flair));
final boolean isNsfw = submission.isNsfw();
if (isNsfw) {
b.sheet(3, nsfw, res.getString(R.string.mod_btn_unmark_nsfw));
} else {
b.sheet(3, nsfw, res.getString(R.string.mod_btn_mark_nsfw));
}
final boolean isSpoiler = submission.getDataNode().get("spoiler").asBoolean();
if (isSpoiler) {
b.sheet(12, nsfw, "Unmark as spoiler");
} else {
b.sheet(12, nsfw, "Mark as spoiler");
}
final boolean locked = submission.isLocked();
if (locked) {
b.sheet(9, lock, "Unlock thread");
} else {
b.sheet(9, lock, "Lock thread");
}
final boolean stickied = submission.isStickied();
if (stickied) {
b.sheet(4, pin, res.getString(R.string.mod_btn_unpin));
} else {
b.sheet(4, pin, res.getString(R.string.mod_btn_pin));
}
final boolean distinguished = submission.getDistinguishedStatus() == DistinguishedStatus.MODERATOR || submission.getDistinguishedStatus() == DistinguishedStatus.ADMIN;
if (submission.getAuthor().equalsIgnoreCase(Authentication.name)) {
if (distinguished) {
b.sheet(5, distinguish, "Undistingiush");
} else {
b.sheet(5, distinguish, "Distinguish");
}
}
final String finalWhoApproved = whoApproved;
final boolean finalApproved = approved;
b.sheet(8, profile, res.getString(R.string.mod_btn_author));
b.sheet(23, ban, mContext.getString(R.string.mod_ban_user));
b.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
new AsyncTask<Void, Void, ArrayList<String>>() {
@Override
protected ArrayList<String> doInBackground(Void... params) {
ArrayList<String> finalReports = new ArrayList<>();
for (Map.Entry<String, Integer> entry : reports.entrySet()) {
finalReports.add(entry.getValue() + "× " + entry.getKey());
}
for (Map.Entry<String, String> entry : reports2.entrySet()) {
finalReports.add(entry.getKey() + ": " + entry.getValue());
}
if (finalReports.isEmpty()) {
finalReports.add(mContext.getString(R.string.mod_no_reports));
}
return finalReports;
}
@Override
public void onPostExecute(ArrayList<String> data) {
new AlertDialogWrapper.Builder(mContext).setTitle(R.string.mod_reports).setItems(data.toArray(new CharSequence[data.size()]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case 1:
if (finalApproved) {
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, finalWhoApproved);
mContext.startActivity(i);
} else {
approveSubmission(mContext, posts, submission, recyclerview, holder);
}
break;
case 2:
// todo this
break;
case 3:
if (isNsfw) {
unNsfwSubmission(mContext, submission, holder);
} else {
setPostNsfw(mContext, submission, holder);
}
break;
case 12:
if (isSpoiler) {
unSpoiler(mContext, submission, holder);
} else {
setSpoiler(mContext, submission, holder);
}
break;
case 9:
if (locked) {
unLockSubmission(mContext, submission, holder);
} else {
lockSubmission(mContext, submission, holder);
}
break;
case 4:
if (stickied) {
unStickySubmission(mContext, submission, holder);
} else {
stickySubmission(mContext, submission, holder);
}
break;
case 5:
if (distinguished) {
unDistinguishSubmission(mContext, submission, holder);
} else {
distinguishSubmission(mContext, submission, holder);
}
break;
case 6:
removeSubmission(mContext, submission, posts, recyclerview, holder, false);
break;
case 7:
doRemoveSubmissionReason(mContext, submission, posts, recyclerview, holder);
break;
case 30:
removeSubmission(mContext, submission, posts, recyclerview, holder, true);
break;
case 8:
Intent i = new Intent(mContext, Profile.class);
i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
mContext.startActivity(i);
break;
case 20:
doSetFlair(mContext, submission, holder);
break;
case 23:
// ban a user
showBan(mContext, holder.itemView, submission, "", "", "", "");
break;
}
}
});
b.show();
}
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();
}
Aggregations