77using Android ;
88using Android . Annotation ;
99using Android . App ;
10+ using Android . Content ;
11+ using Android . Content . PM ;
1012using Android . Graphics ;
1113using Android . Graphics . Drawables ;
1214using Android . OS ;
15+ using Android . Runtime ;
1316using Android . Support . V4 . App ;
1417using Android . Support . V4 . Content ;
1518using Android . Support . V7 . App ;
1821using Android . Views ;
1922using Android . Widget ;
2023using CheeseBind ;
24+ using Java . IO ;
2125using System ;
2226using System . Linq ;
2327using System . Text ;
2428using System . Threading ;
25- using Java . IO ;
2629using System . Threading . Tasks ;
2730
2831namespace MaterialDialogs . Sample
@@ -69,7 +72,7 @@ void ShowToast(int message)
6972 protected override void OnCreate ( Bundle bundle )
7073 {
7174 base . OnCreate ( bundle ) ;
72- SetContentView ( Resource . Layout . activity_main ) ;
75+ SetContentView ( Resource . Layout . activity_main ) ;
7376 Cheeseknife . Bind ( this ) ;
7477
7578 _handler = new Handler ( ) ;
@@ -235,7 +238,7 @@ public void ShowListLongItems(object sender, EventArgs e)
235238 . ItemsCallback ( ( dialog , view , which , text ) => ShowToast ( $ "{ which } : { text } ") )
236239 . Show ( ) ;
237240 }
238-
241+
239242 [ OnClick ( Resource . Id . list_checkPrompt ) ]
240243 public void ShowListCheckPrompt ( object sender , EventArgs e )
241244 {
@@ -249,7 +252,7 @@ public void ShowListCheckPrompt(object sender, EventArgs e)
249252 }
250253
251254 static int index = 0 ;
252-
255+
253256 [ OnClick ( Resource . Id . list_longPress ) ]
254257 public void ShowListLongPress ( object sender , EventArgs e )
255258 {
@@ -259,7 +262,7 @@ public void ShowListLongPress(object sender, EventArgs e)
259262 . Items ( Resource . Array . socialNetworks )
260263 . ItemsCallback ( ( dialog , view , which , text ) => ShowToast ( $ "{ which } : { text } ") )
261264 . AutoDismiss ( false )
262- . ItemsLongCallback ( ( dialog , itemView , position , text ) =>
265+ . ItemsLongCallback ( ( dialog , itemView , position , text ) =>
263266 {
264267 dialog . GetItems ( ) . RemoveAt ( position ) ;
265268 dialog . NotifyItemsChanged ( ) ;
@@ -502,7 +505,7 @@ public void ShowCustomView(object sender, EventArgs e)
502505 } ;
503506
504507 int widgetColor = ThemeSingleton . Get ( ) . WidgetColor ;
505- MDTintHelper . SetTint ( checkbox ,
508+ MDTintHelper . SetTint ( checkbox ,
506509 widgetColor == 0 ? ContextCompat . GetColor ( this , Resource . Color . accent ) : widgetColor ) ;
507510
508511 MDTintHelper . SetTint ( _passwordInput ,
@@ -561,7 +564,7 @@ public void ShowColorChooserCustomColors(object sender, EventArgs e)
561564 {
562565 int [ ] [ ] subColors = new int [ ] [ ]
563566 {
564- new int [ ]
567+ new int [ ]
565568 {
566569 Color . ParseColor ( "#EF5350" ) . ToArgb ( ) ,
567570 Color . ParseColor ( "#F44336" ) . ToArgb ( ) ,
@@ -688,7 +691,7 @@ public void ShowShowCancelDismissCallbacks(object sender, EventArgs e)
688691 . Show ( ) ;
689692 }
690693
691- [ TargetApi ( Value = ( int ) BuildVersionCodes . JellyBean ) ]
694+ [ TargetApi ( Value = ( int ) BuildVersionCodes . JellyBean ) ]
692695 [ OnClick ( Resource . Id . file_chooser ) ]
693696 public void ShowFileChooser ( object sender , EventArgs e )
694697 {
@@ -822,14 +825,14 @@ public void ShowProgressDeterminateDialog(object sender, EventArgs e)
822825 . Content ( Resource . String . please_wait )
823826 . ContentGravity ( GravityEnum . Center )
824827 . Progress ( false , 150 , true )
825- . CancelListener ( dialog =>
828+ . CancelListener ( dialog =>
826829 {
827830 _cancellationTokenSrc ? . Cancel ( ) ;
828831 } )
829- . ShowListener ( dialogInterface =>
832+ . ShowListener ( dialogInterface =>
830833 {
831834 MaterialDialog dialog = ( MaterialDialog ) dialogInterface ;
832- StartThread ( async ( ) =>
835+ StartThread ( async ( ) =>
833836 {
834837 while ( dialog . CurrentProgress != dialog . MaxProgress )
835838 {
@@ -842,7 +845,7 @@ public void ShowProgressDeterminateDialog(object sender, EventArgs e)
842845
843846 dialog . IncrementProgress ( 1 ) ;
844847 }
845- RunOnUiThread ( ( ) =>
848+ RunOnUiThread ( ( ) =>
846849 {
847850 dialog . SetContent ( GetString ( Resource . String . md_done_label ) ) ;
848851 } ) ;
@@ -873,5 +876,56 @@ void ShowIndeterminateProgressDialog(bool horizontal)
873876 }
874877
875878 #endregion
879+
880+ #region Preferences
881+
882+ [ OnClick ( Resource . Id . preference_dialogs ) ]
883+ public void ShowPreferenceDialogs ( object sender , EventArgs e )
884+ {
885+ if ( Build . VERSION . SdkInt > BuildVersionCodes . GingerbreadMr1 )
886+ {
887+ StartActivity ( new Intent ( ApplicationContext , typeof ( PreferenceActivity ) ) ) ;
888+ }
889+ else
890+ {
891+ StartActivity ( new Intent ( ApplicationContext , typeof ( PreferenceActivityCompat ) ) ) ;
892+ }
893+ }
894+
895+ #endregion
896+
897+ public override bool OnCreateOptionsMenu ( IMenu menu )
898+ {
899+ MenuInflater . Inflate ( Resource . Menu . main , menu ) ;
900+ return base . OnCreateOptionsMenu ( menu ) ;
901+ }
902+
903+ public override bool OnOptionsItemSelected ( IMenuItem item )
904+ {
905+ if ( item . ItemId == Resource . Id . about )
906+ {
907+ AboutDialog . Show ( this ) ;
908+ return true ;
909+ }
910+ return base . OnOptionsItemSelected ( item ) ;
911+ }
912+
913+ public override void OnRequestPermissionsResult ( int requestCode , string [ ] permissions , [ GeneratedEnum ] Permission [ ] grantResults )
914+ {
915+ base . OnRequestPermissionsResult ( requestCode , permissions , grantResults ) ;
916+
917+ if ( requestCode == StoragePermissionRC )
918+ {
919+ if ( grantResults [ 0 ] == Permission . Granted )
920+ {
921+ _handler . PostDelayed ( ( ) => FindViewById ( _chooserDialog ) . PerformClick ( ) , 1000 ) ;
922+ }
923+ else
924+ {
925+ Toast . MakeText ( this , "The folder or file chooser will not work without " +
926+ "permission to read external storage." , ToastLength . Long ) . Show ( ) ;
927+ }
928+ }
929+ }
876930 }
877931}
0 commit comments