MaterialDialog.java 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. package com.afollestad.materialdialogs;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.res.ColorStateList;
  6. import android.content.res.Resources;
  7. import android.content.res.TypedArray;
  8. import android.database.DataSetObserver;
  9. import android.graphics.Color;
  10. import android.graphics.Paint;
  11. import android.graphics.Typeface;
  12. import android.graphics.drawable.Drawable;
  13. import android.os.Build;
  14. import android.support.annotation.ArrayRes;
  15. import android.support.annotation.ColorRes;
  16. import android.support.annotation.DrawableRes;
  17. import android.support.annotation.LayoutRes;
  18. import android.support.annotation.NonNull;
  19. import android.support.annotation.Nullable;
  20. import android.support.annotation.StringRes;
  21. import android.text.method.LinkMovementMethod;
  22. import android.util.Log;
  23. import android.view.ContextThemeWrapper;
  24. import android.view.Gravity;
  25. import android.view.LayoutInflater;
  26. import android.view.View;
  27. import android.view.ViewGroup;
  28. import android.widget.AdapterView;
  29. import android.widget.ArrayAdapter;
  30. import android.widget.CheckBox;
  31. import android.widget.ImageView;
  32. import android.widget.LinearLayout;
  33. import android.widget.ListAdapter;
  34. import android.widget.ListView;
  35. import android.widget.RadioButton;
  36. import android.widget.RelativeLayout;
  37. import android.widget.ScrollView;
  38. import android.widget.TextView;
  39. import com.afollestad.materialdialogs.base.DialogBase;
  40. import com.afollestad.materialdialogs.views.MeasureCallbackListView;
  41. import com.afollestad.materialdialogs.views.MeasureCallbackScrollView;
  42. import java.util.ArrayList;
  43. import java.util.Arrays;
  44. import java.util.List;
  45. /**
  46. * @author Aidan Follestad (afollestad)
  47. */
  48. public class MaterialDialog extends DialogBase implements View.OnClickListener, MeasureCallbackScrollView.Callback, MeasureCallbackListView.Callback {
  49. private ImageView icon;
  50. private TextView title;
  51. private View titleFrame;
  52. private Context mContext;
  53. private CharSequence positiveText;
  54. private TextView positiveButton;
  55. private CharSequence neutralText;
  56. private TextView neutralButton;
  57. private CharSequence negativeText;
  58. private TextView negativeButton;
  59. private View view;
  60. private ListView listView;
  61. private int positiveColor;
  62. private int negativeColor;
  63. private int neutralColor;
  64. private SimpleCallback callback;
  65. private ListCallback listCallback;
  66. private ListCallback listCallbackSingle;
  67. private ListCallbackMulti listCallbackMulti;
  68. private View customView;
  69. private CharSequence[] items;
  70. private boolean isStacked;
  71. private int selectedIndex;
  72. private Integer[] selectedIndices;
  73. private boolean mMeasuredScrollView;
  74. private Typeface mediumFont;
  75. private Typeface regularFont;
  76. private boolean autoDismiss;
  77. private ListAdapter adapter;
  78. private ListType listType;
  79. private List<Integer> selectedIndicesList;
  80. protected static ContextThemeWrapper getTheme(Builder builder) {
  81. TypedArray a = builder.context.getTheme().obtainStyledAttributes(new int[]{R.attr.md_dark_theme});
  82. boolean darkTheme = builder.theme == Theme.DARK;
  83. if (!darkTheme) {
  84. try {
  85. darkTheme = a.getBoolean(0, false);
  86. } finally {
  87. a.recycle();
  88. }
  89. }
  90. return new ContextThemeWrapper(builder.context, darkTheme ? R.style.MD_Dark : R.style.MD_Light);
  91. }
  92. protected MaterialDialog(Builder builder) {
  93. super(getTheme(builder));
  94. this.regularFont = builder.regularFont;
  95. if (this.regularFont == null)
  96. this.regularFont = Typeface.createFromAsset(getContext().getResources().getAssets(), "Roboto-Regular.ttf");
  97. this.mediumFont = builder.mediumFont;
  98. if (this.mediumFont == null)
  99. this.mediumFont = Typeface.createFromAsset(getContext().getResources().getAssets(), "Roboto-Medium.ttf");
  100. mContext = builder.context;
  101. this.view = LayoutInflater.from(getContext()).inflate(R.layout.md_dialog, null);
  102. this.customView = builder.customView;
  103. this.callback = builder.callback;
  104. this.listCallback = builder.listCallback;
  105. this.listCallbackSingle = builder.listCallbackSingle;
  106. this.listCallbackMulti = builder.listCallbackMulti;
  107. this.positiveText = builder.positiveText;
  108. this.neutralText = builder.neutralText;
  109. this.negativeText = builder.negativeText;
  110. this.items = builder.items;
  111. this.setCancelable(builder.cancelable);
  112. this.selectedIndex = builder.selectedIndex;
  113. this.selectedIndices = builder.selectedIndicies;
  114. this.autoDismiss = builder.autoDismiss;
  115. this.adapter = builder.adapter;
  116. this.positiveColor = builder.positiveColor;
  117. this.negativeColor = builder.negativeColor;
  118. this.neutralColor = builder.neutralColor;
  119. final int mdAccentColor = DialogUtils.resolveColor(mContext, R.attr.md_accent_color);
  120. if (mdAccentColor != 0) {
  121. if (this.positiveColor == 0) this.positiveColor = mdAccentColor;
  122. if (this.negativeColor == 0) this.negativeColor = mdAccentColor;
  123. if (this.neutralColor == 0) this.neutralColor = mdAccentColor;
  124. }
  125. title = (TextView) view.findViewById(R.id.title);
  126. icon = (ImageView) view.findViewById(R.id.icon);
  127. titleFrame = view.findViewById(R.id.titleFrame);
  128. final TextView content = (TextView) view.findViewById(R.id.content);
  129. content.setText(builder.content);
  130. content.setMovementMethod(new LinkMovementMethod());
  131. setTypeface(content, regularFont);
  132. content.setLineSpacing(0f, builder.contentLineSpacingMultiplier);
  133. if (this.positiveColor == 0) {
  134. content.setLinkTextColor(DialogUtils.resolveColor(getContext(), android.R.attr.textColorPrimary));
  135. } else {
  136. content.setLinkTextColor(this.positiveColor);
  137. }
  138. if (builder.contentAlignment == Alignment.CENTER) {
  139. content.setGravity(Gravity.CENTER_HORIZONTAL);
  140. } else if (builder.contentAlignment == Alignment.RIGHT) {
  141. content.setGravity(Gravity.RIGHT);
  142. }
  143. if (customView != null) {
  144. title = (TextView) view.findViewById(R.id.titleCustomView);
  145. icon = (ImageView) view.findViewById(R.id.iconCustomView);
  146. titleFrame = view.findViewById(R.id.titleFrameCustomView);
  147. invalidateCustomViewAssociations();
  148. ((LinearLayout) view.findViewById(R.id.customViewFrame)).addView(customView);
  149. } else {
  150. invalidateCustomViewAssociations();
  151. }
  152. if (builder.icon != null) {
  153. icon.setVisibility(View.VISIBLE);
  154. icon.setImageDrawable(builder.icon);
  155. } else {
  156. icon.setVisibility(View.GONE);
  157. }
  158. boolean adapterProvided = adapter != null;
  159. if (items != null && items.length > 0 || adapterProvided) {
  160. title = (TextView) view.findViewById(R.id.titleCustomView);
  161. listView = (ListView) view.findViewById(R.id.contentListView);
  162. ((MeasureCallbackListView) listView).setCallback(this);
  163. if (!adapterProvided) {
  164. // Determine list type
  165. if (listCallbackSingle != null) {
  166. listType = ListType.SINGLE;
  167. } else if (listCallbackMulti != null) {
  168. listType = ListType.MULTI;
  169. selectedIndicesList = new ArrayList<>(Arrays.asList(selectedIndices));
  170. } else {
  171. listType = ListType.REGULAR;
  172. }
  173. adapter = new MaterialDialogAdapter(mContext, ListType.getLayoutForType(listType), R.id.title, items);
  174. }
  175. adapter.registerDataSetObserver(new DataSetObserver() {
  176. @Override
  177. public void onChanged() {
  178. super.onChanged();
  179. listView.post(new Runnable() {
  180. @Override
  181. public void run() {
  182. invalidateCustomViewAssociations();
  183. }
  184. });
  185. }
  186. });
  187. }
  188. // Title is set after it's determined whether to use first title or custom view title
  189. if (builder.title == null || builder.title.toString().trim().length() == 0) {
  190. titleFrame.setVisibility(View.GONE);
  191. if (customView == null)
  192. view.findViewById(R.id.titleFrameCustomView).setVisibility(View.GONE);
  193. } else {
  194. title.setText(builder.title);
  195. setTypeface(title, mediumFont);
  196. if (builder.titleColor != -1) {
  197. title.setTextColor(builder.titleColor);
  198. } else {
  199. final int fallback = DialogUtils.resolveColor(getContext(), android.R.attr.textColorPrimary);
  200. title.setTextColor(DialogUtils.resolveColor(getContext(), R.attr.md_title_color, fallback));
  201. }
  202. if (builder.titleAlignment == Alignment.CENTER) {
  203. title.setGravity(Gravity.CENTER_HORIZONTAL);
  204. } else if (builder.titleAlignment == Alignment.RIGHT) {
  205. title.setGravity(Gravity.RIGHT);
  206. }
  207. }
  208. if (builder.contentColor != -1) {
  209. content.setTextColor(builder.contentColor);
  210. } else {
  211. final int fallback = DialogUtils.resolveColor(getContext(), android.R.attr.textColorSecondary);
  212. content.setTextColor(DialogUtils.resolveColor(getContext(), R.attr.md_content_color, fallback));
  213. }
  214. invalidateActions();
  215. setOnShowListenerInternal();
  216. setViewInternal(view);
  217. if (builder.theme == Theme.LIGHT && Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
  218. setInverseBackgroundForced(true);
  219. title.setTextColor(Color.BLACK);
  220. content.setTextColor(Color.BLACK);
  221. }
  222. }
  223. @Override
  224. public void onShow(DialogInterface dialog) {
  225. super.onShow(dialog); // calls any external show listeners
  226. checkIfStackingNeeded();
  227. invalidateCustomViewAssociations();
  228. }
  229. /**
  230. * Invalidates visibility of views for the presence of a custom view or list content
  231. */
  232. private void invalidateCustomViewAssociations() {
  233. if (customView != null || (items != null && items.length > 0) || adapter != null) {
  234. view.findViewById(R.id.mainFrame).setVisibility(View.GONE);
  235. view.findViewById(R.id.customViewScrollParent).setVisibility(View.VISIBLE);
  236. if (!mMeasuredScrollView && listView == null) {
  237. // Wait until it's measured
  238. ((MeasureCallbackScrollView) view.findViewById(R.id.customViewScroll)).setCallback(this);
  239. return;
  240. }
  241. if (canCustomViewScroll()) {
  242. view.findViewById(R.id.customViewDivider).setVisibility(View.VISIBLE);
  243. view.findViewById(R.id.customViewDivider).setBackgroundColor(DialogUtils.resolveColor(getContext(), R.attr.md_divider));
  244. setMargin(view.findViewById(R.id.buttonStackedFrame), -1, 0, -1, -1);
  245. setMargin(view.findViewById(R.id.buttonDefaultFrame), -1, 0, -1, -1);
  246. if (items != null && items.length > 0) {
  247. View customFrame = view.findViewById(R.id.customViewFrame);
  248. Resources r = getContext().getResources();
  249. int bottomPadding = view.findViewById(R.id.titleCustomView).getVisibility() == View.VISIBLE ?
  250. (int) r.getDimension(R.dimen.md_main_frame_margin) : (int) r.getDimension(R.dimen.md_dialog_frame_margin);
  251. customFrame.setPadding(customFrame.getPaddingLeft(), customFrame.getPaddingTop(),
  252. customFrame.getPaddingRight(), bottomPadding);
  253. }
  254. } else {
  255. view.findViewById(R.id.customViewDivider).setVisibility(View.GONE);
  256. final int bottomMargin = (int) getContext().getResources().getDimension(R.dimen.md_button_padding_frame_bottom);
  257. setMargin(view.findViewById(R.id.buttonStackedFrame), -1, bottomMargin, -1, -1);
  258. setMargin(view.findViewById(R.id.buttonDefaultFrame), -1, bottomMargin, -1, -1);
  259. }
  260. } else {
  261. view.findViewById(R.id.mainFrame).setVisibility(View.VISIBLE);
  262. view.findViewById(R.id.customViewScrollParent).setVisibility(View.GONE);
  263. view.findViewById(R.id.customViewDivider).setVisibility(View.GONE);
  264. if (!mMeasuredScrollView) {
  265. // Wait until it's measured
  266. ((MeasureCallbackScrollView) view.findViewById(R.id.contentScrollView)).setCallback(this);
  267. return;
  268. }
  269. if (canContentScroll()) {
  270. view.findViewById(R.id.customViewDivider).setVisibility(View.VISIBLE);
  271. view.findViewById(R.id.customViewDivider).setBackgroundColor(DialogUtils.resolveColor(getContext(), R.attr.md_divider));
  272. setMargin(view.findViewById(R.id.mainFrame), -1, 0, -1, -1);
  273. setMargin(view.findViewById(R.id.buttonStackedFrame), -1, 0, -1, -1);
  274. setMargin(view.findViewById(R.id.buttonDefaultFrame), -1, 0, -1, -1);
  275. final int conPadding = (int) getContext().getResources().getDimension(R.dimen.md_main_frame_margin);
  276. View con = view.findViewById(R.id.content);
  277. con.setPadding(con.getPaddingLeft(), 0, con.getPaddingRight(), conPadding);
  278. } else {
  279. View con = view.findViewById(R.id.content);
  280. con.setPadding(con.getPaddingLeft(), 0, con.getPaddingRight(), 0);
  281. }
  282. }
  283. }
  284. /**
  285. * Invalidates the radio buttons in the single choice mode list so that only the radio button that
  286. * was previous selected is checked.
  287. */
  288. private void invalidateSingleChoice(int newSelection) {
  289. newSelection++;
  290. final LinearLayout list = (LinearLayout) view.findViewById(R.id.customViewFrame);
  291. for (int i = 1; i < list.getChildCount(); i++) {
  292. View v = list.getChildAt(i);
  293. @SuppressLint("WrongViewCast")
  294. RadioButton rb = (RadioButton) v.findViewById(R.id.control);
  295. if (newSelection != i) {
  296. rb.setChecked(false);
  297. rb.clearFocus();
  298. }
  299. }
  300. }
  301. /**
  302. * Constructs the dialog's list content and sets up click listeners.
  303. */
  304. private void invalidateList() {
  305. if ((items == null || items.length == 0) && adapter == null) return;
  306. // Hide content
  307. view.findViewById(R.id.contentScrollView).setVisibility(View.GONE);
  308. // Show custom frame container but hide the scrollview
  309. view.findViewById(R.id.customViewScrollParent).setVisibility(View.VISIBLE);
  310. view.findViewById(R.id.customViewScroll).setVisibility(View.GONE);
  311. // Setup margins on custom view frame
  312. LinearLayout customFrame = (LinearLayout) view.findViewById(R.id.customViewFrame);
  313. setMargin(customFrame, -1, -1, 0, 0);
  314. // Set up list with adapter
  315. LinearLayout listViewContainer = (LinearLayout) view.findViewById(R.id.list_view_container);
  316. listViewContainer.setVisibility(View.VISIBLE);
  317. listView.setAdapter(adapter);
  318. if (listType != null) {
  319. // Only set listener for 1st-party adapter, leave custom adapter implementation to user with getListView()
  320. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  321. @Override
  322. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  323. if (listType == ListType.MULTI) {
  324. // Keep our selected items up to date
  325. boolean isChecked = !((CheckBox) view.findViewById(R.id.control)).isChecked(); // Inverted because the view's click listener is called before the check is toggled
  326. boolean previouslySelected = selectedIndicesList.contains(position);
  327. if (isChecked) {
  328. if (!previouslySelected) {
  329. selectedIndicesList.add(position);
  330. }
  331. } else if (previouslySelected) {
  332. selectedIndicesList.remove(Integer.valueOf(position));
  333. }
  334. } else if (listType == ListType.SINGLE) {
  335. // Keep our selected item up to date
  336. if (selectedIndex != position) {
  337. selectedIndex = position;
  338. ((MaterialDialogAdapter) adapter).notifyDataSetChanged();
  339. }
  340. }
  341. onClick(view);
  342. }
  343. });
  344. }
  345. final int dialogFramePadding = (int) mContext.getResources().getDimension(R.dimen.md_dialog_frame_margin);
  346. final int mainFramePadding = (int) mContext.getResources().getDimension(R.dimen.md_main_frame_margin);
  347. if (titleFrame.getVisibility() == View.VISIBLE || icon.getVisibility() == View.VISIBLE) {
  348. final int customFramePadding = (int) getContext().getResources().getDimension(R.dimen.md_title_margin_plainlist);
  349. title.setPadding(customFramePadding, dialogFramePadding, customFramePadding, title.getPaddingBottom());
  350. ViewGroup titleFrame = (ViewGroup) title.getParent();
  351. ((ViewGroup) titleFrame.getParent()).removeView(titleFrame);
  352. listViewContainer.addView(titleFrame, 0);
  353. } else {
  354. listView.setPadding(listView.getPaddingLeft(), mainFramePadding,
  355. listView.getPaddingRight(), listView.getPaddingBottom());
  356. }
  357. }
  358. private int calculateMaxButtonWidth() {
  359. /**
  360. * Max button width = (DialogWidth - 16dp - 16dp - 8dp) / 2
  361. * From: http://www.google.com/design/spec/components/dialogs.html#dialogs-specs
  362. */
  363. final int dialogWidth = getWindow().getDecorView().getMeasuredWidth();
  364. final int eightDp = (int) getContext().getResources().getDimension(R.dimen.md_button_padding_horizontal_external);
  365. final int sixteenDp = (int) getContext().getResources().getDimension(R.dimen.md_button_padding_frame_side);
  366. return (dialogWidth - sixteenDp - sixteenDp - eightDp) / 2;
  367. }
  368. /**
  369. * Detects whether or not the custom view or list content can be scrolled.
  370. */
  371. private boolean canCustomViewScroll() {
  372. if (listView != null) {
  373. return listView.getLastVisiblePosition() != -1 && listView.getLastVisiblePosition() < (listView.getCount() - 1);
  374. }
  375. final ScrollView scrollView = (ScrollView) view.findViewById(R.id.customViewScroll);
  376. final int childHeight = view.findViewById(R.id.customViewFrame).getMeasuredHeight();
  377. return scrollView.getMeasuredHeight() < childHeight;
  378. }
  379. /**
  380. * Detects whether or not the content TextView can be scrolled.
  381. */
  382. private boolean canContentScroll() {
  383. final ScrollView scrollView = (ScrollView) view.findViewById(R.id.contentScrollView);
  384. final int childHeight = view.findViewById(R.id.content).getMeasuredHeight();
  385. return scrollView.getMeasuredHeight() < childHeight;
  386. }
  387. /**
  388. * Measures the action button's and their text to decide whether or not the button should be stacked.
  389. */
  390. private void checkIfStackingNeeded() {
  391. if (numberOfActionButtons() <= 1) {
  392. Log.v("MD_Stacking", "Less than or equal to 1 button, stacking isn't needed.");
  393. return;
  394. }
  395. final int maxWidth = calculateMaxButtonWidth();
  396. Log.v("MD_Stacking", "Max button width: " + maxWidth);
  397. final Paint paint = positiveButton.getPaint();
  398. final int eightDp = (int) getContext().getResources().getDimension(R.dimen.md_button_padding_horizontal_external);
  399. isStacked = false;
  400. if (this.positiveText != null) {
  401. final int positiveWidth = (int) paint.measureText(positiveButton.getText().toString()) + eightDp;
  402. isStacked = positiveWidth > maxWidth;
  403. Log.v("MD_Stacking", "Positive button width: " + positiveWidth);
  404. } else {
  405. Log.v("MD_Stacking", "No positive button");
  406. }
  407. if (!isStacked && this.neutralText != null) {
  408. final int neutralWidth = (int) paint.measureText(neutralButton.getText().toString()) + eightDp;
  409. isStacked = neutralWidth > maxWidth;
  410. Log.v("MD_Stacking", "Neutral button width: " + neutralWidth);
  411. } else {
  412. Log.v("MD_Stacking", "No neutral button or already stacked");
  413. }
  414. if (!isStacked && this.negativeText != null) {
  415. final int negativeWidth = (int) paint.measureText(negativeButton.getText().toString()) + eightDp;
  416. isStacked = negativeWidth > maxWidth;
  417. Log.v("MD_Stacking", "Negative button width: " + negativeWidth);
  418. } else {
  419. Log.v("MD_Stacking", "No negative button or already stacked");
  420. }
  421. invalidateActions();
  422. }
  423. /**
  424. * Invalidates the positive/neutral/negative action buttons. Decides whether they should be visible
  425. * and sets their properties (such as height, text color, etc.).
  426. */
  427. private boolean invalidateActions() {
  428. if (!hasActionButtons()) {
  429. // If the dialog is a plain list dialog, no buttons are shown.
  430. view.findViewById(R.id.buttonDefaultFrame).setVisibility(View.GONE);
  431. view.findViewById(R.id.buttonStackedFrame).setVisibility(View.GONE);
  432. invalidateList();
  433. return false;
  434. }
  435. if (isStacked) {
  436. view.findViewById(R.id.buttonDefaultFrame).setVisibility(View.GONE);
  437. view.findViewById(R.id.buttonStackedFrame).setVisibility(View.VISIBLE);
  438. } else {
  439. view.findViewById(R.id.buttonDefaultFrame).setVisibility(View.VISIBLE);
  440. view.findViewById(R.id.buttonStackedFrame).setVisibility(View.GONE);
  441. }
  442. positiveButton = (TextView) view.findViewById(
  443. isStacked ? R.id.buttonStackedPositive : R.id.buttonDefaultPositive);
  444. if (this.positiveText != null) {
  445. setTypeface(positiveButton, mediumFont);
  446. positiveButton.setText(this.positiveText);
  447. positiveButton.setTextColor(getActionTextStateList(this.positiveColor));
  448. setBackgroundCompat(positiveButton, DialogUtils.resolveDrawable(getContext(), R.attr.md_selector));
  449. positiveButton.setTag(POSITIVE);
  450. positiveButton.setOnClickListener(this);
  451. } else {
  452. positiveButton.setVisibility(View.GONE);
  453. }
  454. neutralButton = (TextView) view.findViewById(
  455. isStacked ? R.id.buttonStackedNeutral : R.id.buttonDefaultNeutral);
  456. if (this.neutralText != null) {
  457. setTypeface(neutralButton, mediumFont);
  458. neutralButton.setVisibility(View.VISIBLE);
  459. neutralButton.setTextColor(getActionTextStateList(this.neutralColor));
  460. setBackgroundCompat(neutralButton, DialogUtils.resolveDrawable(getContext(), R.attr.md_selector));
  461. neutralButton.setText(this.neutralText);
  462. neutralButton.setTag(NEUTRAL);
  463. neutralButton.setOnClickListener(this);
  464. } else {
  465. neutralButton.setVisibility(View.GONE);
  466. }
  467. negativeButton = (TextView) view.findViewById(
  468. isStacked ? R.id.buttonStackedNegative : R.id.buttonDefaultNegative);
  469. if (this.negativeText != null) {
  470. setTypeface(negativeButton, mediumFont);
  471. negativeButton.setVisibility(View.VISIBLE);
  472. negativeButton.setTextColor(getActionTextStateList(this.negativeColor));
  473. setBackgroundCompat(negativeButton, DialogUtils.resolveDrawable(getContext(), R.attr.md_selector));
  474. negativeButton.setText(this.negativeText);
  475. negativeButton.setTag(NEGATIVE);
  476. negativeButton.setOnClickListener(this);
  477. if (!isStacked) {
  478. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
  479. RelativeLayout.LayoutParams.WRAP_CONTENT,
  480. (int) getContext().getResources().getDimension(R.dimen.md_button_height));
  481. if (this.positiveText != null) {
  482. params.addRule(RelativeLayout.LEFT_OF, R.id.buttonDefaultPositive);
  483. } else {
  484. params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  485. }
  486. negativeButton.setLayoutParams(params);
  487. }
  488. } else {
  489. negativeButton.setVisibility(View.GONE);
  490. }
  491. invalidateList();
  492. return true;
  493. }
  494. private void sendSingleChoiceCallback(View v) {
  495. CharSequence text = null;
  496. if (selectedIndex >= 0) {
  497. text = items[selectedIndex];
  498. }
  499. listCallbackSingle.onSelection(this, v, selectedIndex, text);
  500. }
  501. private void sendMultichoiceCallback() {
  502. List<CharSequence> selectedTitles = new ArrayList<CharSequence>();
  503. for (Integer i : selectedIndicesList) {
  504. selectedTitles.add(items[i]);
  505. }
  506. listCallbackMulti.onSelection(this,
  507. selectedIndicesList.toArray(new Integer[selectedIndicesList.size()]),
  508. selectedTitles.toArray(new CharSequence[selectedTitles.size()]));
  509. }
  510. @Override
  511. public final void onClick(View v) {
  512. String tag = (String) v.getTag();
  513. if (tag.equals(POSITIVE)) {
  514. if (listCallbackSingle != null) {
  515. if (autoDismiss) dismiss();
  516. sendSingleChoiceCallback(v);
  517. } else if (listCallbackMulti != null) {
  518. if (autoDismiss) dismiss();
  519. sendMultichoiceCallback();
  520. } else if (callback != null) {
  521. if (autoDismiss) dismiss();
  522. callback.onPositive(this);
  523. } else if (autoDismiss) dismiss();
  524. } else if (tag.equals(NEGATIVE)) {
  525. if (callback != null && callback instanceof Callback) {
  526. if (autoDismiss) dismiss();
  527. ((Callback) callback).onNegative(this);
  528. } else if (autoDismiss) dismiss();
  529. } else if (tag.equals(NEUTRAL)) {
  530. if (callback != null && callback instanceof FullCallback) {
  531. if (autoDismiss) dismiss();
  532. ((FullCallback) callback).onNeutral(this);
  533. } else if (autoDismiss) dismiss();
  534. } else {
  535. String[] split = tag.split(":");
  536. int index = Integer.parseInt(split[0]);
  537. if (listCallback != null) {
  538. if (autoDismiss) dismiss();
  539. listCallback.onSelection(this, v, index, split[1]);
  540. } else if (listCallbackSingle != null) {
  541. RadioButton cb = (RadioButton) ((LinearLayout) v).getChildAt(0);
  542. if (!cb.isChecked())
  543. cb.setChecked(true);
  544. invalidateSingleChoice(index);
  545. if (positiveText == null) {
  546. // Immediately send the selection callback if no positive button is shown
  547. if (autoDismiss) dismiss();
  548. sendSingleChoiceCallback(v);
  549. }
  550. } else if (listCallbackMulti != null) {
  551. CheckBox cb = (CheckBox) ((LinearLayout) v).getChildAt(0);
  552. cb.setChecked(!cb.isChecked());
  553. if (positiveText == null) {
  554. // Immediately send the selection callback if no positive button is shown
  555. if (autoDismiss) dismiss();
  556. sendMultichoiceCallback();
  557. }
  558. } else if (autoDismiss) dismiss();
  559. }
  560. }
  561. @Override
  562. public void onMeasureScroll(ScrollView view) {
  563. if (view.getMeasuredWidth() > 0) {
  564. mMeasuredScrollView = true;
  565. invalidateCustomViewAssociations();
  566. }
  567. }
  568. @Override
  569. public void onMeasureList(ListView view) {
  570. invalidateCustomViewAssociations();
  571. }
  572. /**
  573. * The class used to construct a MaterialDialog.
  574. */
  575. public static class Builder {
  576. protected Context context;
  577. protected CharSequence title;
  578. protected Alignment titleAlignment = Alignment.LEFT;
  579. protected Alignment contentAlignment = Alignment.LEFT;
  580. protected int titleColor = -1;
  581. protected int contentColor = -1;
  582. protected CharSequence content;
  583. protected CharSequence[] items;
  584. protected CharSequence positiveText;
  585. protected CharSequence neutralText;
  586. protected CharSequence negativeText;
  587. protected View customView;
  588. protected int positiveColor;
  589. protected int negativeColor;
  590. protected int neutralColor;
  591. protected SimpleCallback callback;
  592. protected ListCallback listCallback;
  593. protected ListCallback listCallbackSingle;
  594. protected ListCallbackMulti listCallbackMulti;
  595. protected Theme theme = Theme.LIGHT;
  596. protected boolean cancelable = true;
  597. protected float contentLineSpacingMultiplier = 1.3f;
  598. protected int selectedIndex = -1;
  599. protected Integer[] selectedIndicies = null;
  600. protected boolean autoDismiss = true;
  601. protected Typeface regularFont;
  602. protected Typeface mediumFont;
  603. protected Drawable icon;
  604. protected ListAdapter adapter;
  605. public Builder(@NonNull Context context) {
  606. this.context = context;
  607. final int materialBlue = context.getResources().getColor(R.color.md_material_blue_500);
  608. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  609. TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorAccent});
  610. try {
  611. this.positiveColor = a.getColor(0, materialBlue);
  612. this.negativeColor = a.getColor(0, materialBlue);
  613. this.neutralColor = a.getColor(0, materialBlue);
  614. } catch (Exception e) {
  615. this.positiveColor = materialBlue;
  616. this.negativeColor = materialBlue;
  617. this.neutralColor = materialBlue;
  618. } finally {
  619. a.recycle();
  620. }
  621. } else {
  622. TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorAccent});
  623. try {
  624. this.positiveColor = a.getColor(0, materialBlue);
  625. this.negativeColor = a.getColor(0, materialBlue);
  626. this.neutralColor = a.getColor(0, materialBlue);
  627. } catch (Exception e) {
  628. this.positiveColor = materialBlue;
  629. this.negativeColor = materialBlue;
  630. this.neutralColor = materialBlue;
  631. } finally {
  632. a.recycle();
  633. }
  634. }
  635. }
  636. public Builder title(@StringRes int titleRes) {
  637. title(this.context.getString(titleRes));
  638. return this;
  639. }
  640. public Builder title(CharSequence title) {
  641. this.title = title;
  642. return this;
  643. }
  644. public Builder titleAlignment(Alignment align) {
  645. this.titleAlignment = align;
  646. return this;
  647. }
  648. public Builder titleColorRes(@ColorRes int colorRes) {
  649. titleColor(this.context.getResources().getColor(colorRes));
  650. return this;
  651. }
  652. /**
  653. * Sets the fonts used in the dialog.
  654. *
  655. * @param medium The font used on titles and action buttons. Null uses the default.
  656. * @param regular The font used everywhere else, like on the content and list items. Null uses the default.
  657. * @return The Builder instance so you can chain calls to it.
  658. */
  659. public Builder typeface(Typeface medium, Typeface regular) {
  660. this.mediumFont = medium;
  661. this.regularFont = regular;
  662. return this;
  663. }
  664. public Builder titleColor(int color) {
  665. this.titleColor = color;
  666. return this;
  667. }
  668. public Builder icon(Drawable icon) {
  669. this.icon = icon;
  670. return this;
  671. }
  672. public Builder icon(@DrawableRes int icon) {
  673. this.icon = context.getResources().getDrawable(icon);
  674. return this;
  675. }
  676. public Builder iconAttr(int iconAttr) {
  677. this.icon = DialogUtils.resolveDrawable(context, iconAttr);
  678. return this;
  679. }
  680. public Builder contentColor(int color) {
  681. this.contentColor = color;
  682. return this;
  683. }
  684. public Builder contentColorRes(@ColorRes int colorRes) {
  685. contentColor(this.context.getResources().getColor(colorRes));
  686. return this;
  687. }
  688. public Builder content(@StringRes int contentRes) {
  689. content(this.context.getString(contentRes));
  690. return this;
  691. }
  692. public Builder content(CharSequence content) {
  693. this.content = content;
  694. return this;
  695. }
  696. public Builder content(@StringRes int contentRes, Object... formatArgs) {
  697. content(this.context.getString(contentRes, formatArgs));
  698. return this;
  699. }
  700. public Builder contentAlignment(Alignment align) {
  701. this.contentAlignment = align;
  702. return this;
  703. }
  704. public Builder contentLineSpacing(float multiplier) {
  705. this.contentLineSpacingMultiplier = multiplier;
  706. return this;
  707. }
  708. public Builder items(@ArrayRes int itemsRes) {
  709. items(this.context.getResources().getStringArray(itemsRes));
  710. return this;
  711. }
  712. public Builder items(CharSequence[] items) {
  713. this.items = items;
  714. return this;
  715. }
  716. public Builder itemsCallback(ListCallback callback) {
  717. this.listCallback = callback;
  718. this.listCallbackSingle = null;
  719. this.listCallbackMulti = null;
  720. return this;
  721. }
  722. /**
  723. * Pass anything below 0 (such as -1) for the selected index to leave all options unselected initially.
  724. * Otherwise pass the index of an item that will be selected initially.
  725. *
  726. * @param selectedIndex The checkbox index that will be selected initially.
  727. * @param callback The callback that will be called when the presses the positive button.
  728. * @return The Builder instance so you can chain calls to it.
  729. */
  730. public Builder itemsCallbackSingleChoice(int selectedIndex, ListCallback callback) {
  731. this.selectedIndex = selectedIndex;
  732. this.listCallback = null;
  733. this.listCallbackSingle = callback;
  734. this.listCallbackMulti = null;
  735. return this;
  736. }
  737. /**
  738. * Pass null for the selected indices to leave all options unselected initially. Otherwise pass
  739. * an array of indices that will be selected initially.
  740. *
  741. * @param selectedIndices The radio button indices that will be selected initially.
  742. * @param callback The callback that will be called when the presses the positive button.
  743. * @return The Builder instance so you can chain calls to it.
  744. */
  745. public Builder itemsCallbackMultiChoice(Integer[] selectedIndices, ListCallbackMulti callback) {
  746. this.selectedIndicies = selectedIndices;
  747. this.listCallback = null;
  748. this.listCallbackSingle = null;
  749. this.listCallbackMulti = callback;
  750. return this;
  751. }
  752. public Builder positiveText(@StringRes int postiveRes) {
  753. positiveText(this.context.getString(postiveRes));
  754. return this;
  755. }
  756. public Builder positiveText(CharSequence message) {
  757. this.positiveText = message;
  758. return this;
  759. }
  760. public Builder neutralText(@StringRes int neutralRes) {
  761. neutralText(this.context.getString(neutralRes));
  762. return this;
  763. }
  764. public Builder neutralText(CharSequence message) {
  765. this.neutralText = message;
  766. return this;
  767. }
  768. public Builder negativeText(@StringRes int negativeRes) {
  769. negativeText(this.context.getString(negativeRes));
  770. return this;
  771. }
  772. public Builder negativeText(CharSequence message) {
  773. this.negativeText = message;
  774. return this;
  775. }
  776. public Builder customView(@LayoutRes int layoutRes) {
  777. LayoutInflater li = LayoutInflater.from(this.context);
  778. customView(li.inflate(layoutRes, null));
  779. return this;
  780. }
  781. public Builder customView(View view) {
  782. this.customView = view;
  783. return this;
  784. }
  785. public Builder positiveColorRes(@ColorRes int colorRes) {
  786. positiveColor(this.context.getResources().getColor(colorRes));
  787. return this;
  788. }
  789. public Builder positiveColor(int color) {
  790. this.positiveColor = color;
  791. return this;
  792. }
  793. public Builder negativeColorRes(@ColorRes int colorRes) {
  794. negativeColor(this.context.getResources().getColor(colorRes));
  795. return this;
  796. }
  797. public Builder negativeColor(int color) {
  798. this.negativeColor = color;
  799. return this;
  800. }
  801. public Builder neutralColorRes(@ColorRes int colorRes) {
  802. neutralColor(this.context.getResources().getColor(colorRes));
  803. return this;
  804. }
  805. public Builder neutralColor(int color) {
  806. this.neutralColor = color;
  807. return this;
  808. }
  809. public Builder callback(SimpleCallback callback) {
  810. this.callback = callback;
  811. return this;
  812. }
  813. public Builder theme(Theme theme) {
  814. this.theme = theme;
  815. return this;
  816. }
  817. public Builder cancelable(boolean cancelable) {
  818. this.cancelable = cancelable;
  819. return this;
  820. }
  821. /**
  822. * This defaults to true. If set to false, the dialog will not automatically be dismissed
  823. * when an action button is pressed, and not automatically dismissed when the user selects
  824. * a list item.
  825. *
  826. * @param dismiss Whether or not to dismiss the dialog automatically.
  827. * @return The Builder instance so you can chain calls to it.
  828. */
  829. public Builder autoDismiss(boolean dismiss) {
  830. this.autoDismiss = dismiss;
  831. return this;
  832. }
  833. /**
  834. * Sets a custom {@link android.widget.ListAdapter} for the dialog's list
  835. *
  836. * @return This Builder object to allow for chaining of calls to set methods
  837. */
  838. public Builder adapter(ListAdapter adapter) {
  839. this.adapter = adapter;
  840. return this;
  841. }
  842. public MaterialDialog build() {
  843. return new MaterialDialog(this);
  844. }
  845. public MaterialDialog show() {
  846. MaterialDialog dialog = new MaterialDialog(this);
  847. dialog.show();
  848. return dialog;
  849. }
  850. }
  851. private ColorStateList getActionTextStateList(int newPrimaryColor) {
  852. final int fallBackButtonColor = DialogUtils.resolveColor(getContext(), android.R.attr.textColorPrimary);
  853. if (newPrimaryColor == 0) newPrimaryColor = fallBackButtonColor;
  854. int[][] states = new int[][]{
  855. new int[]{-android.R.attr.state_enabled}, // disabled
  856. new int[]{} // enabled
  857. };
  858. int[] colors = new int[]{
  859. DialogUtils.adjustAlpha(newPrimaryColor, 0.4f),
  860. newPrimaryColor
  861. };
  862. return new ColorStateList(states, colors);
  863. }
  864. /**
  865. * Retrieves the view of an action button, allowing you to modify properties such as whether or not it's enabled.
  866. *
  867. * @param which The action button of which to get the view for.
  868. * @return The view from the dialog's layout representing this action button.
  869. */
  870. public final View getActionButton(DialogAction which) {
  871. if (view == null) return null;
  872. if (isStacked) {
  873. switch (which) {
  874. default:
  875. return view.findViewById(R.id.buttonStackedPositive);
  876. case NEUTRAL:
  877. return view.findViewById(R.id.buttonStackedNeutral);
  878. case NEGATIVE:
  879. return view.findViewById(R.id.buttonStackedNegative);
  880. }
  881. } else {
  882. switch (which) {
  883. default:
  884. return view.findViewById(R.id.buttonDefaultPositive);
  885. case NEUTRAL:
  886. return view.findViewById(R.id.buttonDefaultNeutral);
  887. case NEGATIVE:
  888. return view.findViewById(R.id.buttonDefaultNegative);
  889. }
  890. }
  891. }
  892. /**
  893. * Retrieves the frame view containing the title and icon. You can manually change visibility and retrieve children.
  894. */
  895. public final View getTitleFrame() {
  896. return titleFrame;
  897. }
  898. /**
  899. * Retrieves the custom view that was inflated or set to the MaterialDialog during building.
  900. *
  901. * @return The custom view that was passed into the Builder.
  902. */
  903. public final View getCustomView() {
  904. return customView;
  905. }
  906. /**
  907. * Updates an action button's title, causing invalidation to check if the action buttons should be stacked.
  908. *
  909. * @param which The action button to update.
  910. * @param title The new title of the action button.
  911. */
  912. public final void setActionButton(DialogAction which, CharSequence title) {
  913. switch (which) {
  914. default:
  915. this.positiveText = title;
  916. break;
  917. case NEUTRAL:
  918. this.neutralText = title;
  919. break;
  920. case NEGATIVE:
  921. this.negativeText = title;
  922. break;
  923. }
  924. invalidateActions();
  925. }
  926. /**
  927. * Updates an action button's title, causing invalidation to check if the action buttons should be stacked.
  928. *
  929. * @param which The action button to update.
  930. * @param titleRes The string resource of the new title of the action button.
  931. */
  932. public final void setActionButton(DialogAction which, @StringRes int titleRes) {
  933. setActionButton(which, getContext().getString(titleRes));
  934. }
  935. /**
  936. * Gets whether or not the positive, neutral, or negative action button is visible.
  937. *
  938. * @return Whether or not 1 or more action buttons is visible.
  939. */
  940. public final boolean hasActionButtons() {
  941. return numberOfActionButtons() > 0;
  942. }
  943. /**
  944. * Gets the number of visible action buttons.
  945. *
  946. * @return 0 through 3, depending on how many should be or are visible.
  947. */
  948. public final int numberOfActionButtons() {
  949. int number = 0;
  950. if (positiveText != null) number++;
  951. if (neutralText != null) number++;
  952. if (negativeText != null) number++;
  953. return number;
  954. }
  955. /**
  956. * Updates the dialog's title.
  957. */
  958. public final void setTitle(CharSequence title) {
  959. this.title.setText(title);
  960. }
  961. @Override
  962. public void setIcon(int resId) {
  963. icon.setImageResource(resId);
  964. icon.setVisibility(resId != 0 ? View.VISIBLE : View.GONE);
  965. }
  966. @Override
  967. public void setIcon(Drawable d) {
  968. icon.setImageDrawable(d);
  969. icon.setVisibility(d != null ? View.VISIBLE : View.GONE);
  970. }
  971. @Override
  972. public void setIconAttribute(int attrId) {
  973. Drawable d = DialogUtils.resolveDrawable(getContext(), attrId);
  974. icon.setImageDrawable(d);
  975. icon.setVisibility(d != null ? View.VISIBLE : View.GONE);
  976. }
  977. public final void setContent(CharSequence content) {
  978. ((TextView) view.findViewById(R.id.content)).setText(content);
  979. }
  980. public final void setItems(CharSequence[] items) {
  981. if (adapter == null)
  982. throw new IllegalStateException("This MaterialDialog instance does not yet have an adapter set to it. You cannot use setItems().");
  983. if (adapter instanceof MaterialDialogAdapter) {
  984. adapter = new MaterialDialogAdapter(mContext, ListType.getLayoutForType(listType), R.id.title, items);
  985. } else {
  986. throw new IllegalStateException("When using a custom adapter, setItems() cannot be used. Set items through the adapter instead.");
  987. }
  988. this.items = items;
  989. listView.setAdapter(adapter);
  990. invalidateCustomViewAssociations();
  991. }
  992. /**
  993. * Use this to customize any list-specific logic for this dialog (OnItemClickListener, OnLongItemClickListener, etc.)
  994. *
  995. * @return The ListView instance used by this dialog, or null if not using a list.
  996. */
  997. @Nullable
  998. public ListView getListView() {
  999. return listView;
  1000. }
  1001. private class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
  1002. final int itemColor = DialogUtils.resolveColor(getContext(), android.R.attr.textColorSecondary);
  1003. public MaterialDialogAdapter(Context context, int resource, int textViewResourceId, CharSequence[] objects) {
  1004. super(context, resource, textViewResourceId, objects);
  1005. }
  1006. @Override
  1007. public boolean hasStableIds() {
  1008. return true;
  1009. }
  1010. @Override
  1011. public long getItemId(int position) {
  1012. return position;
  1013. }
  1014. @SuppressLint("WrongViewCast")
  1015. @Override
  1016. public View getView(final int index, View convertView, ViewGroup parent) {
  1017. final View view = super.getView(index, convertView, parent);
  1018. TextView tv = (TextView) view.findViewById(R.id.title);
  1019. switch (listType) {
  1020. case SINGLE:
  1021. RadioButton radio = (RadioButton) view.findViewById(R.id.control);
  1022. radio.setChecked(selectedIndex == index);
  1023. break;
  1024. case MULTI:
  1025. if (selectedIndices != null) {
  1026. CheckBox checkbox = (CheckBox) view.findViewById(R.id.control);
  1027. checkbox.setChecked(selectedIndicesList.contains(index));
  1028. }
  1029. break;
  1030. }
  1031. tv.setText(items[index]);
  1032. tv.setTextColor(itemColor);
  1033. setTypeface(tv, regularFont);
  1034. view.setTag(index + ":" + items[index]);
  1035. return view;
  1036. }
  1037. }
  1038. private static enum ListType {
  1039. REGULAR, SINGLE, MULTI;
  1040. public static int getLayoutForType(ListType type) {
  1041. switch (type) {
  1042. case REGULAR:
  1043. return R.layout.md_listitem;
  1044. case SINGLE:
  1045. return R.layout.md_listitem_singlechoice;
  1046. case MULTI:
  1047. return R.layout.md_listitem_multichoice;
  1048. default:
  1049. // Shouldn't be possible
  1050. throw new IllegalArgumentException("Not a valid list type");
  1051. }
  1052. }
  1053. }
  1054. public static interface ListCallback {
  1055. void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text);
  1056. }
  1057. public static interface ListCallbackMulti {
  1058. void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text);
  1059. }
  1060. public static interface SimpleCallback {
  1061. void onPositive(MaterialDialog dialog);
  1062. }
  1063. public static interface Callback extends SimpleCallback {
  1064. void onNegative(MaterialDialog dialog);
  1065. }
  1066. public static interface FullCallback extends Callback {
  1067. void onNeutral(MaterialDialog dialog);
  1068. }
  1069. }