Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit df6aff5

Browse files
committed
Preferences, about dialog
1 parent 09b3b4a commit df6aff5

File tree

6 files changed

+173
-14
lines changed

6 files changed

+173
-14
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using AFollestad.MaterialDialogs;
2+
using Android.App;
3+
using Android.OS;
4+
using Android.Support.V7.App;
5+
6+
using DialogFragment = Android.Support.V4.App.DialogFragment;
7+
8+
namespace MaterialDialogs.Sample
9+
{
10+
public class AboutDialog : DialogFragment
11+
{
12+
public static void Show(AppCompatActivity context)
13+
{
14+
var dialog = new AboutDialog();
15+
dialog.Show(context.SupportFragmentManager, "[ABOUT_DIALOG]");
16+
}
17+
18+
public override Dialog OnCreateDialog(Bundle savedInstanceState)
19+
{
20+
return new MaterialDialog.Builder(Activity)
21+
.Title(Resource.String.about)
22+
.PositiveText(Resource.String.dismiss)
23+
.Content(Resource.String.about_body, true)
24+
.ContentLineSpacing(1.6f)
25+
.Build();
26+
}
27+
}
28+
}

MaterialDialogs.Sample/MainActivity.cs

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
using Android;
88
using Android.Annotation;
99
using Android.App;
10+
using Android.Content;
11+
using Android.Content.PM;
1012
using Android.Graphics;
1113
using Android.Graphics.Drawables;
1214
using Android.OS;
15+
using Android.Runtime;
1316
using Android.Support.V4.App;
1417
using Android.Support.V4.Content;
1518
using Android.Support.V7.App;
@@ -18,11 +21,11 @@
1821
using Android.Views;
1922
using Android.Widget;
2023
using CheeseBind;
24+
using Java.IO;
2125
using System;
2226
using System.Linq;
2327
using System.Text;
2428
using System.Threading;
25-
using Java.IO;
2629
using System.Threading.Tasks;
2730

2831
namespace 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
}

MaterialDialogs.Sample/MaterialDialogs.Sample.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@
102102
</Reference>
103103
</ItemGroup>
104104
<ItemGroup>
105+
<Compile Include="AboutDialog.cs" />
105106
<Compile Include="ButtonItemAdapter.cs" />
106107
<Compile Include="ChangelogDialog.cs" />
107108
<Compile Include="MainActivity.cs" />
109+
<Compile Include="PreferenceActivity.cs" />
110+
<Compile Include="PreferenceActivityCompat.cs" />
108111
<Compile Include="Resources\Resource.Designer.cs" />
109112
<Compile Include="Properties\AssemblyInfo.cs" />
110113
</ItemGroup>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Android.App;
2+
using Android.OS;
3+
using Android.Preferences;
4+
using Android.Support.V7.App;
5+
using Android.Views;
6+
7+
namespace MaterialDialogs.Sample
8+
{
9+
[Activity(Label="@string/preference_dialogs")]
10+
public class PreferenceActivity : AppCompatActivity
11+
{
12+
public class SettingsFragment : PreferenceFragment
13+
{
14+
public override void OnCreate(Bundle savedInstanceState)
15+
{
16+
base.OnCreate(savedInstanceState);
17+
AddPreferencesFromResource(Resource.Xml.preferences);
18+
}
19+
}
20+
21+
protected override void OnCreate(Bundle savedInstanceState)
22+
{
23+
base.OnCreate(savedInstanceState);
24+
SetContentView(Resource.Layout.preference_activity_custom);
25+
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
26+
27+
if (FragmentManager.FindFragmentById(Resource.Id.content_frame) == null)
28+
{
29+
FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, new SettingsFragment()).Commit();
30+
}
31+
}
32+
33+
public override bool OnOptionsItemSelected(IMenuItem item)
34+
{
35+
if (item.ItemId == Android.Resource.Id.Home)
36+
{
37+
OnBackPressed();
38+
return true;
39+
}
40+
return base.OnOptionsItemSelected(item);
41+
}
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Android.Annotation;
2+
using Android.App;
3+
using Android.OS;
4+
using Android.Views;
5+
6+
namespace MaterialDialogs.Sample
7+
{
8+
[TargetApi(Value=(int)BuildVersionCodes.GingerbreadMr1)]
9+
[Activity(Label = "@string/preference_dialogs")]
10+
public class PreferenceActivityCompat : Android.Preferences.PreferenceActivity
11+
{
12+
protected override void OnCreate(Bundle savedInstanceState)
13+
{
14+
base.OnCreate(savedInstanceState);
15+
AddPreferencesFromResource(Resource.Xml.preferences);
16+
}
17+
18+
public override bool OnOptionsItemSelected(IMenuItem item)
19+
{
20+
if (item.ItemId == Android.Resource.Id.Home)
21+
{
22+
OnBackPressed();
23+
return true;
24+
}
25+
return base.OnOptionsItemSelected(item);
26+
}
27+
}
28+
}

MaterialDialogs.Sample/Resources/values/strings.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
<string name="connect">Connect</string>
3232

3333
<string name="about">About</string>
34-
<string name="about_body"><![CDATA[
34+
<string name="about_body">
35+
<![CDATA[
3536
material-dialogs, a library designed by <b>Aidan Follestad</b>.<br/>
3637
<a href=\'http://aidanfollestad.com\'>Website</a>&nbsp;&nbsp;
3738
<a href=\'https://twitter.com/afollestad\'>Twitter</a>&nbsp;&nbsp;
3839
<a href=\'https://google.com/+AidanFollestad\'>Google+</a>&nbsp;&nbsp;
3940
<a href=\'https://github.com/afollestad\'>GitHub</a>&nbsp;&nbsp;
40-
<a href=\'https://www.linkedin.com/in/afollestad\'>LinkedIn</a>
41+
<a href=\'https://www.linkedin.com/in/afollestad\'>LinkedIn</a><br/><br/>
42+
Xamaring Binding by <b>Dominik Minta</b><br/>
43+
<a href=\'https://github.com/dminta/MaterialDialogsXamarinAndroidBinding\'>GitHub</a>
4144
]]></string>
4245
<string name="dismiss">Dismiss</string>
4346
<string name="basic_notitle">Basic (No Title)</string>

0 commit comments

Comments
 (0)