use of android.support.v7.app.AlertDialog in project instructure-android by instructure.
the class CalendarChooserDialogStyled method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final FragmentActivity activity = getActivity();
final CalendarChooserAdapter listAdapter = new CalendarChooserAdapter(activity, android.R.layout.select_dialog_multichoice);
final ListView listView = new ListView(activity);
listView.setAdapter(listAdapter);
// Override onItemCLick to implement "checking" behavior and handle contextsForReturn
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckBox checkBox = view.findViewById(R.id.checkBox);
String contextId = "";
if (view.getTag() instanceof ViewHolder) {
contextId = ((ViewHolder) view.getTag()).contextId;
}
if (checkBox.isChecked()) {
checkBox.setChecked(false);
removeSelection(position, contextId);
} else {
if (mSelectedIds.size() >= 10) {
Toast.makeText(activity, getResources().getString(R.string.calendarDialog10Warning), Toast.LENGTH_SHORT).show();
} else {
checkBox.setChecked(true);
addSelection(position, contextId);
}
}
}
});
final AlertDialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.selectCanvasCalendars).setView(listView).setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mSelectedIds.size() > 0) {
if (mCallback != null) {
if (selectionChanged()) {
// We only want to refresh if a change was made
mCallback.onCalendarsSelected(getSelectedContexts());
}
} else {
Toast.makeText(activity, R.string.errorOccurred, Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
} else {
Toast.makeText(activity, getResources().getString(R.string.calendarDialogNoneWarning), Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mSelectedIds.size() < 1) {
Toast.makeText(activity, getResources().getString(R.string.calendarDialogNoneWarning), Toast.LENGTH_SHORT).show();
} else {
if (mCallback != null) {
if (mIsFirstShow) {
// We only want to make a call here if it's their first time (on negative)
mCallback.onCalendarsSelected(getSelectedContexts());
}
}
dialog.dismiss();
}
}
}).setCancelable(false).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mSelectedIds.size() > 0) {
if (mCallback != null) {
if (mIsFirstShow) {
// We only want to make a call here if it's their first time (on negative)
mCallback.onCalendarsSelected(getSelectedContexts());
}
}
}
dialog.dismiss();
}
}).setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
if (mSelectedIds.size() > 0) {
if (mCallback != null) {
if (mIsFirstShow) {
// We only want to make a call here if it's their first time (on negative)
mCallback.onCalendarsSelected(getSelectedContexts());
}
}
}
dialog.dismiss();
return true;
}
return false;
}
}).create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface useless) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ThemePrefs.getBrandColor());
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ThemePrefs.getBrandColor());
}
});
return dialog;
}
use of android.support.v7.app.AlertDialog in project instructure-android by instructure.
the class QuizQuestionDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final FragmentActivity activity = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.viewQuestions)).setPositiveButton(activity.getString(R.string.okay), null);
// Suppress lint warning about null parent when inflating layout
@SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity()).inflate(R.layout.quiz_question_dialog, null);
listView = view.findViewById(R.id.listview);
builder.setView(view);
final AlertDialog dialog = builder.create();
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface useless) {
CanvasContext course = getArguments().getParcelable(Const.COURSE);
if (course != null) {
int courseColor = ColorKeeper.getOrGenerateColor(course);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(courseColor);
}
}
});
return dialog;
}
use of android.support.v7.app.AlertDialog in project instructure-android by instructure.
the class ShareFileDestinationDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
loadBundleData();
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setView(initViews()).setPositiveButton(R.string.next, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
validateAndShowNext();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismissAllowingStateLoss();
}
}).setCancelable(true).create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
if (alertDialog != null) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ThemePrefs.getButtonColor());
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ThemePrefs.getButtonColor());
}
}
});
return alertDialog;
}
use of android.support.v7.app.AlertDialog in project instructure-android by instructure.
the class WhatIfDialogStyled method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final FragmentActivity activity = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.whatIfDialogText)).setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
final String whatIf = whatIfScore.getText().toString();
callback.onOkayClick(whatIf, Double.parseDouble(totalScore), assignment, position);
}
dismissAllowingStateLoss();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismissAllowingStateLoss();
}
});
@SuppressLint("InflateParams") View view = LayoutInflater.from(activity).inflate(R.layout.what_if_dialog, null);
EditText totalScoreEdit = view.findViewById(R.id.totalScore);
totalScoreEdit.setText(totalScore);
whatIfScore = view.findViewById(R.id.currentScore);
builder.setView(view);
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface worthless) {
if (courseColor != 0) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(courseColor);
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(courseColor);
}
}
});
dialog.setCanceledOnTouchOutside(true);
return dialog;
}
use of android.support.v7.app.AlertDialog in project instructure-android by instructure.
the class RCEInsertDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View root = LayoutInflater.from(getContext()).inflate(R.layout.rce_dialog_insert, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setView(root);
builder.setTitle(getArguments().getString(TITLE));
builder.setPositiveButton(R.string.rce_dialogDone, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mCallback != null) {
mCallback.onResults(mUrlEditText.getText().toString(), mAltEditText.getText().toString());
}
dismiss();
}
});
builder.setNegativeButton(R.string.rce_dialogCancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
final int themeColor = getArguments().getInt(THEME_COLOR, Color.BLACK);
final int highlightColor = RCEUtils.increaseAlpha(themeColor);
final ColorStateList colorStateList = RCEUtils.makeEditTextColorStateList(Color.BLACK, themeColor);
mAltEditText = (AppCompatEditText) root.findViewById(R.id.altEditText);
mUrlEditText = (AppCompatEditText) root.findViewById(R.id.urlEditText);
mAltEditText.setHighlightColor(highlightColor);
mUrlEditText.setHighlightColor(highlightColor);
mAltEditText.setSupportBackgroundTintList(colorStateList);
mUrlEditText.setSupportBackgroundTintList(colorStateList);
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
final int buttonColor = getArguments().getInt(BUTTON_COLOR, Color.BLACK);
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(buttonColor);
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(buttonColor);
}
});
return dialog;
}
Aggregations