Skip to content

Commit

Permalink
calendar: Switch to Material alert dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <[email protected]>
  • Loading branch information
theimpulson committed Oct 19, 2023
1 parent 0d82a79 commit 6df2513
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 30 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/com/android/calendar/DayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.AlertDialog;
import android.app.Service;
import android.content.ContentResolver;
import android.content.ContentUris;
Expand Down Expand Up @@ -80,6 +79,7 @@
import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.settings.GeneralPreferences;
import com.android.calendarcommon2.Time;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -4996,7 +4996,8 @@ public boolean onLongClick(View v) {
flags |= DateUtils.FORMAT_24HOUR;
}
mLongPressTitle = Utils.formatDateRange(mContext, time, time, flags);
new AlertDialog.Builder(mContext).setTitle(mLongPressTitle)
new MaterialAlertDialogBuilder(mContext)
.setTitle(mLongPressTitle)
.setItems(mLongPressItems, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/android/calendar/DeleteEventHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.android.calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
import android.content.ContentValues;
Expand All @@ -32,10 +31,13 @@
import android.widget.ArrayAdapter;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;

import com.android.calendar.event.EditEventHelper;
import com.android.calendar.persistence.CalendarRepository;
import com.android.calendarcommon2.EventRecurrence;
import com.android.calendarcommon2.Time;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -267,7 +269,7 @@ public void delete(long begin, long end, CalendarEventModel model, int which) {
String rRule = model.mRrule;
String originalEvent = model.mOriginalSyncId;
if (TextUtils.isEmpty(rRule)) {
AlertDialog dialog = new AlertDialog.Builder(mContext)
AlertDialog dialog = new MaterialAlertDialogBuilder(mContext)
.setMessage(R.string.delete_this_event_title)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setNegativeButton(android.R.string.cancel, null).create();
Expand Down Expand Up @@ -320,7 +322,7 @@ public void delete(long begin, long end, CalendarEventModel model, int which) {
mWhichIndex = labelIndex;
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_list_item_single_choice, labelArray);
AlertDialog dialog = new AlertDialog.Builder(mContext)
AlertDialog dialog = new MaterialAlertDialogBuilder(mContext)
.setTitle(
mContext.getString(R.string.delete_recurring_event_title,model.mTitle))
.setIconAttribute(android.R.attr.alertDialogIcon)
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/android/calendar/EditResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package com.android.calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import ws.xsoh.etar.R;

/**
Expand Down Expand Up @@ -125,11 +128,13 @@ public void showDialog(int whichEvents) {
if (mDialogListener == null) {
mDialogListener = this;
}
AlertDialog dialog = new AlertDialog.Builder(mParent).setTitle(
R.string.change_response_title).setIconAttribute(android.R.attr.alertDialogIcon)
AlertDialog dialog = new MaterialAlertDialogBuilder(mParent)
.setTitle(R.string.change_response_title)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setSingleChoiceItems(R.array.change_response_labels, whichEvents, mListListener)
.setPositiveButton(android.R.string.ok, mDialogListener)
.setNegativeButton(android.R.string.cancel, null).show();
.setNegativeButton(android.R.string.cancel, null)
.show();
// The caller may set a dismiss listener to hear back when the dialog is
// finished. Use getWhichEvents() to see how the dialog was dismissed.
dialog.setOnDismissListener(this);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/android/calendar/ImportActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.android.calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.DialogInterface;
Expand All @@ -20,6 +19,7 @@
import com.android.calendar.icalendar.IcalendarUtils;
import com.android.calendar.icalendar.VCalendar;
import com.android.calendar.icalendar.VEvent;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.io.File;
import java.text.DateFormat;
Expand Down Expand Up @@ -272,7 +272,7 @@ protected void onPostExecute(final String[] files) {
return;
}

AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(mActivity);
builder.setTitle(R.string.cal_pick_ics)
.setItems(files, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.android.calendar.event;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -36,6 +35,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.android.calendar.AsyncQueryService;
Expand All @@ -46,6 +46,7 @@
import com.android.calendar.settings.GeneralPreferences;
import com.android.calendar.settings.SettingsActivity;
import com.android.calendarcommon2.Time;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -135,7 +136,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
mDate.setText(mDateString);
}

mAlertDialog = new AlertDialog.Builder(activity)
mAlertDialog = new MaterialAlertDialogBuilder(activity)
.setTitle(R.string.new_event_dialog_label)
.setView(view)
.setPositiveButton(R.string.create_event_dialog_save,
Expand Down Expand Up @@ -229,15 +230,16 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

// Find the calendar position in the cursor that matches calendar in
// preference
private void setDefaultCalendarView(Cursor cursor) {
private void setDefaultCalendarView(Context context, Cursor cursor) {
if (cursor == null || cursor.getCount() == 0) {
// Create an error message for the user that, when clicked,
// will exit this activity without saving the event.
final Activity activity = getActivity();
dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.no_syncable_calendars).setIconAttribute(
android.R.attr.alertDialogIcon).setMessage(R.string.no_calendars_found)
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
builder.setTitle(R.string.no_syncable_calendars)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setMessage(R.string.no_calendars_found)
.setPositiveButton(R.string.add_calendar, (dialog, which) -> {
if (activity != null) {
Intent nextIntent = new Intent(activity, SettingsActivity.class);
Expand Down Expand Up @@ -322,7 +324,7 @@ public CalendarQueryService(Context context) {

@Override
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
setDefaultCalendarView(cursor);
setDefaultCalendarView(requireContext(), cursor);
if (cursor != null) {
cursor.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.AsyncQueryHandler;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
Expand Down Expand Up @@ -57,6 +56,7 @@
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand All @@ -76,6 +76,7 @@
import com.android.calendarcommon2.Time;
import com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener;
import com.android.colorpicker.HsvColorComparator;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -506,7 +507,8 @@ protected void displayEditWhichDialog() {
mModifyDialog.dismiss();
mModifyDialog = null;
}
mModifyDialog = new AlertDialog.Builder(mActivity).setTitle(R.string.edit_event_label)
mModifyDialog = new MaterialAlertDialogBuilder(mActivity)
.setTitle(R.string.edit_event_label)
.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/android/calendar/event/EditEventView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.android.calendar.event;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.Service;
Expand Down Expand Up @@ -65,6 +63,7 @@
import android.widget.TextView.OnEditorActionListener;
import android.widget.TimePicker;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
Expand Down Expand Up @@ -94,6 +93,7 @@
import com.android.timezonepicker.TimeZonePickerDialog;
import com.android.timezonepicker.TimeZonePickerUtils;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputEditText;

import java.util.ArrayList;
Expand Down Expand Up @@ -1140,11 +1140,13 @@ public void setCalendarsCursor(Cursor cursor, boolean userVisible, long selected
}
// Create an error message for the user that, when clicked,
// will exit this activity without saving the event.
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(R.string.no_syncable_calendars).setIconAttribute(
android.R.attr.alertDialogIcon).setMessage(R.string.no_calendars_found)
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(mActivity);
builder.setTitle(R.string.no_syncable_calendars)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setMessage(R.string.no_calendars_found)
.setPositiveButton(R.string.add_calendar, this)
.setNegativeButton(android.R.string.no, this).setOnCancelListener(this);
.setNegativeButton(android.R.string.no, this)
.setOnCancelListener(this);
mNoCalendarsDialog = builder.show();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.android.calendar.persistence.CalendarRepository
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputLayout
import ws.xsoh.etar.R

Expand Down Expand Up @@ -55,7 +56,7 @@ class AddOfflineCalendarDialogFragment : DialogFragment() {
}
})

val builder = AlertDialog.Builder(it).apply {
val builder = MaterialAlertDialogBuilder(it).apply {
setView(view)
setTitle(R.string.preferences_list_add_offline_title)
setMessage(R.string.preferences_list_add_offline_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import android.os.Bundle
import android.provider.CalendarContract.Calendars
import android.provider.CalendarContract.Colors
import android.util.SparseIntArray
import androidx.appcompat.app.AlertDialog
import com.android.calendar.AsyncQueryService
import com.android.calendar.Utils
import com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener
import com.android.colorpicker.HsvColorComparator
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import ws.xsoh.etar.R
import java.util.ArrayList
import java.util.Arrays
Expand Down Expand Up @@ -194,7 +194,7 @@ class CalendarColorPickerDialogX : ColorPickerDialogX() {
}

private fun useDefaultColors() {
val warningDialog = AlertDialog.Builder(activity!!)
val warningDialog = MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.preferences_calendar_color_warning_title)
.setMessage(R.string.preferences_calendar_color_warning_message)
.setPositiveButton(R.string.preferences_calendar_color_warning_button) { dialogInterface, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.android.colorpicker.ColorPickerPalette;
import com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

/**
* 1-to-1 Copy of ColorPickerDialog but using androidx classes
Expand Down Expand Up @@ -101,7 +102,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
showPaletteView();
}

mAlertDialog = new AlertDialog.Builder(activity)
mAlertDialog = new MaterialAlertDialogBuilder(activity)
.setTitle(mTitleResId)
.setView(view)
.create();
Expand Down

0 comments on commit 6df2513

Please sign in to comment.