From ad9344567c665f53d73e6bd67eb47efde51f6d01 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Mon, 30 Sep 2019 16:27:29 +0200 Subject: [PATCH] Test search --- AideDeJeu/AideDeJeu.Android/MainActivity.cs | 70 ++++++++++++++++++- .../Properties/AndroidManifest.xml | 6 ++ AideDeJeu/AideDeJeu.Android/testsearch.bat | 2 + AideDeJeu/AideDeJeu/App.xaml.cs | 6 +- .../Views/Library/DeepSearchPage.xaml.cs | 12 ++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 AideDeJeu/AideDeJeu.Android/testsearch.bat diff --git a/AideDeJeu/AideDeJeu.Android/MainActivity.cs b/AideDeJeu/AideDeJeu.Android/MainActivity.cs index d6e33a85..ee05a8c2 100644 --- a/AideDeJeu/AideDeJeu.Android/MainActivity.cs +++ b/AideDeJeu/AideDeJeu.Android/MainActivity.cs @@ -11,8 +11,9 @@ using System.Diagnostics; namespace AideDeJeu.Droid { + [IntentFilter(new[] { Android.Content.Intent.ActionAssist }, Categories = new[] { Android.Content.Intent.CategoryDefault })] //[Activity(Label = "Aide de Jeu", Icon = "@drawable/black_book", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] - [Activity(Label = "Beta Haches & Dés", Icon = "@drawable/battle_axe", Theme = "@style/MyTheme.Splash", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] + [Activity(Name = "com.nioux.aidedejeu.MainActivity", Label = "Beta Haches & Dés", Icon = "@drawable/battle_axe", Theme = "@style/MyTheme.Splash", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) @@ -22,6 +23,9 @@ namespace AideDeJeu.Droid base.OnCreate(bundle); + // Application Level Assistance + //Application.RegisterOnProvideAssistDataListener(new AndroidListener()); + AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException; @@ -38,9 +42,37 @@ namespace AideDeJeu.Droid DisplayCrashReport(); + //// Verify the action and get the query + //if (Android.Content.Intent.ActionSearch == Intent.Action) + //{ + // var query = Intent.GetStringExtra(SearchManager.Query); + //} + + + LoadApplication(new App()); } + protected override void OnNewIntent(Android.Content.Intent intent) + { + base.OnNewIntent(intent); + Intent = intent; + } + + protected override void OnPostResume() + { + base.OnPostResume(); + if (Intent.Extras != null) + { + string search = Intent.Extras.GetString("search"); + if (!string.IsNullOrEmpty(search)) + { + Xamarin.Forms.Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage(search)); + } + Intent.RemoveExtra("search"); + } + } + public override void OnBackPressed() { if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed)) @@ -126,5 +158,41 @@ namespace AideDeJeu.Droid } } + + [IntentFilter(new[] { Android.Content.Intent.ActionAssist }, Categories = new[] { Android.Content.Intent.CategoryDefault })] + //[Activity(Label = "Aide de Jeu", Icon = "@drawable/black_book", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] + [Activity(Name = "com.nioux.aidedejeu.SearchActivity")] + public class SearchActivity : Android.App.Activity // global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity + { + protected override void OnCreate(Bundle bundle) + { + base.OnCreate(bundle); + + // Application Level Assistance + //Application.RegisterOnProvideAssistDataListener(new AndroidListener()); + + // Android.Content.Intent.ActionSearch.Equals + // Verify the action and get the query + if ("com.google.android.gms.actions.SEARCH_ACTION".Equals(Intent.Action)) + { + var query = Intent.GetStringExtra(SearchManager.Query); + System.Diagnostics.Debug.WriteLine(query); + + var intent = new Android.Content.Intent(Android.App.Application.Context, typeof(MainActivity)); + intent.AddFlags(Android.Content.ActivityFlags.NewTask); + intent.PutExtra("search", query); + intent.AddFlags(Android.Content.ActivityFlags.ReorderToFront); + Android.App.Application.Context.StartActivity(intent); + } + this.FinishActivity(0); + } + } + public class AndroidListener : Java.Lang.Object, Application.IOnProvideAssistDataListener + { + public void OnProvideAssistData(Android.App.Activity activity, Bundle data) + { + System.Diagnostics.Debug.WriteLine("OnProvideAssistData"); + } + } } diff --git a/AideDeJeu/AideDeJeu.Android/Properties/AndroidManifest.xml b/AideDeJeu/AideDeJeu.Android/Properties/AndroidManifest.xml index 2c0ccf4d..38eab732 100644 --- a/AideDeJeu/AideDeJeu.Android/Properties/AndroidManifest.xml +++ b/AideDeJeu/AideDeJeu.Android/Properties/AndroidManifest.xml @@ -5,5 +5,11 @@ + + + + + + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu.Android/testsearch.bat b/AideDeJeu/AideDeJeu.Android/testsearch.bat new file mode 100644 index 00000000..b768ea1c --- /dev/null +++ b/AideDeJeu/AideDeJeu.Android/testsearch.bat @@ -0,0 +1,2 @@ +"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query "barde" com.nioux.aidedejeu +pause diff --git a/AideDeJeu/AideDeJeu/App.xaml.cs b/AideDeJeu/AideDeJeu/App.xaml.cs index 8d8094d3..b6d58faa 100644 --- a/AideDeJeu/AideDeJeu/App.xaml.cs +++ b/AideDeJeu/AideDeJeu/App.xaml.cs @@ -16,7 +16,7 @@ namespace AideDeJeu public partial class App : Application { - public App () + public App (string search = null) { InitializeComponent(); @@ -38,6 +38,10 @@ namespace AideDeJeu Routing.RegisterRoute("item", typeof(Views.Library.ItemPage)); //MainPage = mainNavigationPage; //mainNavigationPage.Navigation.PushAsync(new MainPage()); + if (search != null) + { + Shell.Current.Navigation.PushAsync(new Views.Library.DeepSearchPage()); + } } diff --git a/AideDeJeu/AideDeJeu/Views/Library/DeepSearchPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/Library/DeepSearchPage.xaml.cs index 3fa543b6..e5266553 100644 --- a/AideDeJeu/AideDeJeu/Views/Library/DeepSearchPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/Library/DeepSearchPage.xaml.cs @@ -30,6 +30,18 @@ namespace AideDeJeu.Views.Library BindingContext = new DeepSearchViewModel(); } + public DeepSearchPage(string search = null) + { + InitializeComponent(); + + BindingContext = new DeepSearchViewModel(); + + if (search != null) + { + (BindingContext as DeepSearchViewModel).ExecuteSearchCommandAsync(search); + } + } + private async void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e) { var searchedItem = e.Item as SearchedItem;