Skip to content

Commit

Permalink
Merge pull request #423 from LuisAlbertoPenaNunez/feature/422-Hide-ke…
Browse files Browse the repository at this point in the history
…yboard-on-MainPage-when-the-app-start

Hide keyboard on MainPage when the app start
  • Loading branch information
Luis committed Apr 12, 2016
2 parents 1af1af3 + 93a1ef1 commit c72cca3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions Mobile/Android/Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<Compile Include="About\AboutViewModel.cs" />
<Compile Include="About\ContributorAddedEventHandler.cs" />
<Compile Include="Services\EmailService.cs" />
<Compile Include="Services\KeyboardService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down
2 changes: 2 additions & 0 deletions Mobile/Android/Framework/Bootstrapping/Bootstrapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Api.Contract;
using Api;
using APIs;
using Android.Views.InputMethods;

namespace Empleado
{
Expand Down Expand Up @@ -64,6 +65,7 @@ void Run ()
SimpleIoc.Default.Register<IJobsApiService, FakeJobsApiService>();
SimpleIoc.Default.Register<IGithubContributorService, OctocatContributorService>();
SimpleIoc.Default.Register<IEmailService, EmailService> ();
SimpleIoc.Default.Register<IKeyboardService, KeyboardService>();
}
}

Expand Down
24 changes: 18 additions & 6 deletions Mobile/Android/MainPage/MainPageFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Microsoft.Practices.ServiceLocation;
using GalaSoft.MvvmLight.Messaging;
using Android.Support.V4.View;
using Android.Views.InputMethods;
using Core;

namespace Android
{
Expand All @@ -32,6 +34,8 @@ public class MainPageFragment : Android.Support.V4.App.Fragment

IMessenger _messenger;

IKeyboardService _keyboardService;

public override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
Expand All @@ -57,6 +61,8 @@ void GetServices ()
{
_viewModel = ServiceLocator.Current.GetInstance<MainPageFragmentViewModel>();

_keyboardService = ServiceLocator.Current.GetInstance<IKeyboardService>();

_messenger = GalaSoft.MvvmLight.Messaging.Messenger.Default;
}

Expand All @@ -78,9 +84,13 @@ void SetUpScreen()

_searchView.QueryTextChange += OnQueryTextChanged;

_searchView.SetIconifiedByDefault(false);
_searchView.Focusable = true;

_searchView.RequestFocusFromTouch();

_searchView.ClearFocus();

_searchView.SetQueryHint(GetString(Resource.String.HomePageSearchBarHint));
// _searchView.SetQueryHint(GetString(Resource.String.HomePageSearchBarHint));

PersonalizeSearchView();
}
Expand Down Expand Up @@ -119,7 +129,11 @@ public override void OnViewCreated (View view, Bundle savedInstanceState)

void OnSearchLayoutSelected(object sender, EventArgs e)
{
_searchView.RequestFocus();
_searchView.SetIconifiedByDefault(false);

_searchView.RequestFocusFromTouch();

_keyboardService.ShowKeyboard(_searchView);
}

//I know this is wrong, but i will fix this later.
Expand All @@ -128,8 +142,6 @@ void OnSearchLayoutSelected(object sender, EventArgs e)
//So somehow i need to accomplish this task
void OnQuerySubmit(object sender, SearchView.QueryTextSubmitEventArgs e)
{


_viewModel.UserIsTypingCommand.Execute(_searchView.Query);
}

Expand All @@ -149,7 +161,7 @@ public override View OnCreateView (LayoutInflater inflater, ViewGroup container,
{
var view = inflater.Inflate(Resource.Layout.MainPageFragmentLayout, container, false);

_searchLayout = view.FindViewById (Resource.Id.MainSearchLayout);
_searchLayout = view.FindViewById (Resource.Id.segueta);

_locationContainer = view.FindViewById<LinearLayout> (Resource.Id.locationContainer);

Expand Down
2 changes: 2 additions & 0 deletions Mobile/Android/Resources/layout/MainPageFragmentLayout.axml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
app:cardCornerRadius="4dp"
android:layout_margin="5dp">
<LinearLayout
android:id="@+id/segueta"
android:clickable="true"
android:layout_width="match_parent"
android:weightSum="1"
android:layout_height="wrap_content">
Expand Down
36 changes: 36 additions & 0 deletions Mobile/Android/Services/KeyboardService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Core;
using Android.Views.InputMethods;
using Android.Content;
using Android.Views;

namespace Android
{
public class KeyboardService : IKeyboardService
{
InputMethodManager _inputMethodManager;

IContextService _contextService;

public KeyboardService (IContextService contextService)
{
_contextService = contextService;

_inputMethodManager =
((Context)_contextService.GetContext ()).GetSystemService (Context.InputMethodService) as InputMethodManager;
}

public void ShowKeyboard (object focusOver)
{
if(focusOver == null)
throw new ArgumentNullException("focusOver");

var focus = (View) focusOver;

_inputMethodManager.ShowSoftInput(focus, ShowFlags.Forced);

_inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
}
}
}

1 change: 1 addition & 0 deletions Mobile/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Github\GithubUser.cs" />
<Compile Include="Github\OctocatContributorService.cs" />
<Compile Include="Services\IEmailService.cs" />
<Compile Include="IKeyboardService.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions Mobile/Core/IKeyboardService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Core
{
public interface IKeyboardService
{
void ShowKeyboard(object toFocusOn);
}
}

0 comments on commit c72cca3

Please sign in to comment.